Dear All,
I would like to determine whether a given box is is connected to the network and use the NetworkInterface class for this purpose. I use the below code snippet
import java.net.*;
import java.util.Enumeration;
public class TestInterface
{
public static void main(
String s[])
{
Enumeration e = null;
while(true)
{
try{
Thread.sleep(3000);
}
catch(Exception e1)
{
}
try
{
e = NetworkInterface.getNetworkInterfaces();
}
catch(Exception e1)
{
e1.printStackTrace();
}
for (; e.hasMoreElements()
{
NetworkInterface ni=(NetworkInterface)(e.nextElement());
System.out.println(ni.toString());
}
}
}
}
There are two
test I do.
1. By plugging out the ethernet cable
2. By calling /etc/init.d/network stop
In case One I am able to get the response which contains only the Loopback Address
In case two I am able to get the response which contains an Empty list.
But, In one particular box the response is little weired
In case One I am able to get the response which contains both the Loopback Address and the configured eth0 address
In case two I am able to get the response which contains only the eth0 address..
IS there anything i missunderstood, or anything need to be checked in the box on any configuration.
Required your assistance please!!
Swami