Merge pull request #10 from Sevenstax/win_network_interface_fix

Find the network interface by index on windows operating systems.
This commit is contained in:
Marc Mültin 2017-08-30 19:18:15 +02:00 committed by GitHub
commit 47028b4bbd
1 changed files with 10 additions and 2 deletions

View File

@ -65,7 +65,11 @@ public final class MiscUtils {
NetworkInterface nif = null;
try {
nif = NetworkInterface.getByName(networkInterfaceConfig);
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
nif = NetworkInterface.getByIndex(Integer.parseInt(networkInterfaceConfig));
} else {
nif = NetworkInterface.getByName(networkInterfaceConfig);
}
Enumeration<InetAddress> inetAddresses = nif.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
@ -96,7 +100,11 @@ public final class MiscUtils {
byte[] macAddress = null;
try {
nif = NetworkInterface.getByName(networkInterfaceConfig);
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
nif = NetworkInterface.getByIndex(Integer.parseInt(networkInterfaceConfig));
} else {
nif = NetworkInterface.getByName(networkInterfaceConfig);
}
macAddress = nif.getHardwareAddress();
} catch (SocketException e) {
getLogger().error("Failed to retrieve local mac address (SocketException)", e);