Skip to main content

public static String getMacAddr() { try { List all = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface nif : all) { if (!nif.getName().equalsIgnoreCase("wlan0")) continue;

public static String getMacAddr() { try { List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface nif : all) {  if (!nif.getName().equalsIgnoreCase("wlan0")) continue; byte[] macBytes = nif.getHardwareAddress();   if (macBytes == null) {   return "";   }   StringBuilder res1 = new StringBuilder();   for (byte b : macBytes) {   res1.append(String.format("%02X:",b));   }   if (res1.length() > 0) {   res1.deleteCharAt(res1.length() - 1);   }   return res1.toString();   }  } catch (Exception ex) {  }  return "02:00:00:00:00:00"; } 

}

public static String getMacAddr() { try { List all = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface nif : all) { if (!nif.getName().equalsIgnoreCase("wlan0")) continue;

 byte[] macBytes = nif.getHardwareAddress(); if (macBytes == null) { return ""; } StringBuilder res1 = new StringBuilder(); for (byte b : macBytes) { res1.append(String.format("%02X:",b)); } if (res1.length() > 0) { res1.deleteCharAt(res1.length() - 1); } return res1.toString(); } } catch (Exception ex) { } return "02:00:00:00:00:00"; 

}

public static String getMacAddr() { try { List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface nif : all) {  if (!nif.getName().equalsIgnoreCase("wlan0")) continue; byte[] macBytes = nif.getHardwareAddress();   if (macBytes == null) {   return "";   }   StringBuilder res1 = new StringBuilder();   for (byte b : macBytes) {   res1.append(String.format("%02X:",b));   }   if (res1.length() > 0) {   res1.deleteCharAt(res1.length() - 1);   }   return res1.toString();   }  } catch (Exception ex) {  }  return "02:00:00:00:00:00"; } 
Source Link
pm dubey
  • 1k
  • 12
  • 16

public static String getMacAddr() { try { List all = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface nif : all) { if (!nif.getName().equalsIgnoreCase("wlan0")) continue;

 byte[] macBytes = nif.getHardwareAddress(); if (macBytes == null) { return ""; } StringBuilder res1 = new StringBuilder(); for (byte b : macBytes) { res1.append(String.format("%02X:",b)); } if (res1.length() > 0) { res1.deleteCharAt(res1.length() - 1); } return res1.toString(); } } catch (Exception ex) { } return "02:00:00:00:00:00"; 

}