Skip to content

Instantly share code, notes, and snippets.

@jprante
Last active April 18, 2016 20:55
Show Gist options
  • Save jprante/87364ee8d2cebd51e8da023dde66cc45 to your computer and use it in GitHub Desktop.
Save jprante/87364ee8d2cebd51e8da023dde66cc45 to your computer and use it in GitHub Desktop.
Test network interfaces with java
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Collections;
import java.util.Enumeration;
public class NetworkInterfaceTester {
public static void main(String[] args) throws Exception {
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets)) {
System.out.println("checking network interface = " + netint.getName());
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress addr : Collections.list(inetAddresses)) {
System.out.println("found address = " + addr.getHostAddress()
+ " name = " + addr.getHostName()
+ " canicalhostname = " + addr.getCanonicalHostName()
+ " loopback = " + addr.isLoopbackAddress()
+ " sitelocal = " + addr.isSiteLocalAddress()
+ " linklocal = " + addr.isLinkLocalAddress()
+ " anylocal = " + addr.isAnyLocalAddress()
+ " multicast = " + addr.isMulticastAddress()
+ " mcglobal = " + addr.isMCGlobal()
+ " mclinklocal = " + addr.isMCLinkLocal()
+ " mcnodelocal = " + addr.isMCNodeLocal()
+ " mcorglocal = " + addr.isMCOrgLocal()
+ " mcsitelocal = " + addr.isMCSiteLocal()
+ " isReachable = " + addr.isReachable(1000));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment