What is an easy way to track a network adapter in Java?

I want to be able to detect when the computer connects to the network. The environment is Java 5 on Windows.

+1


source to share


2 answers


I think your choice is to either use some JNI library (although I am not familiar with one and which will be platform specific), or just try to connect to a specific IP (Google for example). None of the solutions are elegant, but I don't believe there is a pure Java API for this in 1.5.



In Java 1.6, you can use java.net.NetworkInterface.isUp (), but obviously this won't help in your 1.5 use case.

+2


source


maybe check the flow?



try {
  InetAddress inetAddr = InetAddress.getByName(host);
  setOnline();
} catch (UnknownHostException e) {
  setOffline();
}

      

0


source







All Articles