'Java 5 - Check whether a network interface is up and running.
Java 6 offers isUp() method to check whether a network interface is up and running.
http://docs.oracle.com/javase/6/docs/api/java/net/NetworkInterface.html#isUp()
Is there any way to check the same in Java 5?
Solution 1:[1]
If you won't mind using an external library, check Sigar
You can get the network interface status, among with stats like bytes received or bytes sent.
The only fallback is that is a C library with a java binding, so you will need the specific version for your architecture at runtime
Solution 2:[2]
Class NetworkInterface has a method getInetAddresses(), delivering an enumeration of InetAddress-es. Assuming each adapter supports IPv4, you'll find an Inet4Address among these. if the interface is down it will deliver "0.0.0.0" as address, by method toString(). If an Adapter is up but not linked (no dynamic address assigned), it will have an address of pattern "169.x.x.x".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eugenio Cuevas |
| Solution 2 | Sam Ginrich |
