List of utility methods to do Mac Address Get
String | getMac() get Mac StringBuilder sb = new StringBuilder(); try { InetAddress ip = InetAddress.getLocalHost(); NetworkInterface network = NetworkInterface.getByInetAddress(ip); byte[] mac = network.getHardwareAddress(); for (int i = 0; i < mac.length; i++) { sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "")); } catch (SocketException | UnknownHostException e) { return sb.toString(); |
String | getMacAddr() Retrive mac address for current machine String macAddr = ""; String str = ""; try { NetworkInterface nic = NetworkInterface.getByName("eth0"); if (nic != null) { byte[] buf = nic.getHardwareAddress(); if (buf != null) { for (int i = 0; i < buf.length; i++) { ... |
String | getMacAddress() get Mac Address String result = ""; try { for (NetworkInterface ni : Collections.list(NetworkInterface.getNetworkInterfaces())) { byte[] hardwareAddress = ni.getHardwareAddress(); if (hardwareAddress != null) { for (int i = 0; i < hardwareAddress.length; i++) result += String.format((i == 0 ? "" : "-") + "%02X", hardwareAddress[i]); return result; ... |
String | getMACAddress() get MAC Address StringBuilder sb = new StringBuilder(); try { NetworkInterface network = NetworkInterface.getByInetAddress(ip); byte[] mac = network.getHardwareAddress(); for (int i = 0; i < mac.length; i++) { sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "")); } catch (SocketException e) { ... |
String | getMacAddress() get Mac Address String os = System.getProperty("os.name"); try { if (os.startsWith("Windows")) { return windowsParseMacAddress(windowsRunIpConfigCommand()); } else if (os.startsWith("Linux")) { return linuxParseMacAddress(linuxRunIfConfigCommand()); } else { throw new IOException("unknown operating system: " + os); ... |
byte[] | getMACAddress() Returns the MacAddress of the first physical network interface or a default MacAddress if the there are no network interfaces. if (macAddress == MAC_ADDRESS_DEFAULT) { try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); byte[] mac = null; while (interfaces.hasMoreElements() && (mac == null || mac.length != 6)) { NetworkInterface netInterface = interfaces.nextElement(); if (netInterface.isLoopback() || netInterface.isVirtual()) { continue; ... |
String | getMacAddress() get Mac Address if (macAddress == null) { try { fetchMacAddress(); } catch (Exception e) { e.printStackTrace(); if (macAddress == null) { macAddress = "unknown"; ... |
String | getMacAddress() Returns the MAC address of the first network interface that is found. try { String mac = null; for (NetworkInterface ni : Collections.list(NetworkInterface.getNetworkInterfaces())) { if (ni.getHardwareAddress() != null) { byte[] hwAddr = ni.getHardwareAddress(); if (hwAddr.length > 0) { mac = ""; for (int i = 0; i < hwAddr.length; i++) { ... |
byte[] | getMacAddress() Grabs the mac address of computer and makes it 10 times longer if (cachedMacAddress != null && cachedMacAddress.length >= 10) { return cachedMacAddress; try { Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface network = networkInterfaces.nextElement(); byte[] mac = network.getHardwareAddress(); ... |
String | getMacAddress() get Mac Address return getMacAddress(InetAddress.getLocalHost());
|