Update NetworkInterface.java

Tidied up code, redid the getRealHardwareAddress() method, other one was a clusterfuck.
This commit is contained in:
matt123337
2014-08-15 01:59:48 -04:00
parent 69d0e80b4a
commit 13fcfd3a98
@@ -12,7 +12,7 @@ public class NetworkInterface {
static {
try {
mac = getRealHardwareAddress();
} catch (Exception ignored) {
} catch (SocketException ignored) {
}
}
@@ -20,20 +20,14 @@ public class NetworkInterface {
return mac;
}
public static byte[] getRealHardwareAddress() throws SocketException {
public static byte[] getRealHardwareAddress() throws SocketException{
if (realMac != null)
return realMac;
Enumeration<java.net.NetworkInterface> nis = java.net.NetworkInterface
.getNetworkInterfaces();
while (nis.hasMoreElements()) {
try {
byte[] b = nis.nextElement().getHardwareAddress();
if (b.length == 0)
continue;
return realMac = b;
return realMac = java.net.NetworkInterface.getByInetAddress(
InetAddress.getLocalHost()).getHardwareAddress();
} catch (Exception e) {
}
}
return mac;
}