From 13fcfd3a98925468658d00c2a21be12d2924ff9f Mon Sep 17 00:00:00 2001 From: matt123337 Date: Fri, 15 Aug 2014 01:59:48 -0400 Subject: [PATCH] Update NetworkInterface.java Tidied up code, redid the getRealHardwareAddress() method, other one was a clusterfuck. --- .../core/network/NetworkInterface.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/parabotv2/src/org/parabot/core/network/NetworkInterface.java b/parabotv2/src/org/parabot/core/network/NetworkInterface.java index 363b632..8a21934 100644 --- a/parabotv2/src/org/parabot/core/network/NetworkInterface.java +++ b/parabotv2/src/org/parabot/core/network/NetworkInterface.java @@ -10,29 +10,23 @@ public class NetworkInterface { private static NetworkInterface cached; static { - try { - mac = getRealHardwareAddress(); - } catch (Exception ignored) { - } + try { + mac = getRealHardwareAddress(); + } catch (SocketException ignored) { + } } public byte[] getHardwareAddress() { return mac; } - public static byte[] getRealHardwareAddress() throws SocketException { + public static byte[] getRealHardwareAddress() throws SocketException{ if (realMac != null) return realMac; - Enumeration nis = java.net.NetworkInterface - .getNetworkInterfaces(); - while (nis.hasMoreElements()) { - try { - byte[] b = nis.nextElement().getHardwareAddress(); - if (b.length == 0) - continue; - return realMac = b; - } catch (Exception e) { - } + try { + return realMac = java.net.NetworkInterface.getByInetAddress( + InetAddress.getLocalHost()).getHardwareAddress(); + } catch (Exception e) { } return mac; } @@ -42,4 +36,4 @@ public class NetworkInterface { cached = new NetworkInterface(); return cached; } -} \ No newline at end of file +}