Last active
April 18, 2016 20:55
-
-
Save jprante/87364ee8d2cebd51e8da023dde66cc45 to your computer and use it in GitHub Desktop.
Test network interfaces with java
This file contains hidden or 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
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