mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 08:39:12 +00:00
Update NetworkInterface.java
Tidied up code, redid the getRealHardwareAddress() method, other one was a clusterfuck.
This commit is contained in:
@@ -10,29 +10,23 @@ public class NetworkInterface {
|
|||||||
private static NetworkInterface cached;
|
private static NetworkInterface cached;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
mac = getRealHardwareAddress();
|
mac = getRealHardwareAddress();
|
||||||
} catch (Exception ignored) {
|
} catch (SocketException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getHardwareAddress() {
|
public byte[] getHardwareAddress() {
|
||||||
return mac;
|
return mac;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getRealHardwareAddress() throws SocketException {
|
public static byte[] getRealHardwareAddress() throws SocketException{
|
||||||
if (realMac != null)
|
if (realMac != null)
|
||||||
return realMac;
|
return realMac;
|
||||||
Enumeration<java.net.NetworkInterface> nis = java.net.NetworkInterface
|
try {
|
||||||
.getNetworkInterfaces();
|
return realMac = java.net.NetworkInterface.getByInetAddress(
|
||||||
while (nis.hasMoreElements()) {
|
InetAddress.getLocalHost()).getHardwareAddress();
|
||||||
try {
|
} catch (Exception e) {
|
||||||
byte[] b = nis.nextElement().getHardwareAddress();
|
|
||||||
if (b.length == 0)
|
|
||||||
continue;
|
|
||||||
return realMac = b;
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return mac;
|
return mac;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user