Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×
Java

Journal dmorin's Journal: Detecting a net connection

I've always wanted a way in Java to determine if there is "live" net connectivity on a given machine. That is, if I have a piece of code that's about to try connecting to a machine other than localhost, is there a way to determine if I should even try?

For a long time the answer was no. But JDK1.4 introduced "NetworkInterface" which has potential. I've already written a little utility that looks at a known set of interfaces (such as wlan0 and eth0 on my laptop). If either one is not null, then it assumes network is available. It seems to work correctly -- I yank out my pcmcia net card and it immediately switches to false, I put it back and it goes true again.

The problem is that doesn't work on Windows (apparently). The interface on my NT machine, "lan0", appears to always exist. And on a desktop machine this makes sense, since technically the interface does exist it's just not connected -- that's a different condition.

Is there a way in windows to "down" an interface, like "ifdown" in Linux?

This discussion has been archived. No new comments can be posted.

Detecting a net connection

Comments Filter:

The most exciting phrase to hear in science, the one that heralds new discoveries, is not "Eureka!" (I found it!) but "That's funny ..." -- Isaac Asimov

Working...