• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How the NetworkInterface class behaves in various condition

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic