Created
June 26, 2021 01:07
-
-
Save gubatron/9eac5e1c3272dcfa900ddbc3e68055ef to your computer and use it in GitHub Desktop.
testListingNetworkInterfaces.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void testListingNetworkInterfaces() { | |
try { | |
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); | |
NetworkInterface iface; | |
while (networkInterfaces.hasMoreElements()) { | |
iface = networkInterfaces.nextElement(); | |
LOG.info("displayName:" + iface.getDisplayName() + " " + | |
"index:" + iface.getIndex() + " " + | |
"isUp:" + iface.isUp() + " " + | |
"isVirtual:" + iface.isVirtual() + " " + | |
"name:" + iface.getName() + " " + | |
"MTU:" + iface.getMTU() + " " + | |
"isLoopback:" + iface.isLoopback() + " " + | |
"isPPP:" + iface.isPointToPoint() + " " + | |
"multicastSupport:" + iface.supportsMulticast()); | |
List<InterfaceAddress> interfaceAddresses = iface.getInterfaceAddresses(); | |
if (interfaceAddresses.size() == 0) { | |
LOG.info("no network interfaces for " + iface.getDisplayName()); | |
} else { | |
LOG.info(interfaceAddresses.size() + " network interfaces for " + iface.getDisplayName()); | |
} | |
for (InterfaceAddress address : interfaceAddresses) { | |
LOG.info("hostname:" + address.getAddress().getHostName() + " " | |
+ address.getAddress().toString()); | |
} | |
} | |
} catch (Throwable e) { | |
LOG.error(e.getMessage(), e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment