Skip to content

Instantly share code, notes, and snippets.

@gubatron
Created June 26, 2021 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gubatron/9eac5e1c3272dcfa900ddbc3e68055ef to your computer and use it in GitHub Desktop.
Save gubatron/9eac5e1c3272dcfa900ddbc3e68055ef to your computer and use it in GitHub Desktop.
testListingNetworkInterfaces.java
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