InetAddress.isReachable()

What is the different between, isReachable(NetworkInterface netif, int ttl, int timeout) and isReachable(int timeout) ?

i tried with this..

InetAddress address = InetAddress.getByName("google.com");

System.out.println("Name: " + address.getHostName());

System.out.println("Addr: " + address.getHostAddress());

System.out.println("Reach: " + address.isReachable(3000));

System.out.println("Reach 2: " + address.isReachable(NetworkInterface.getByName("google.com"), 0, 100000));

and i get this

Name: google.com

Addr: 64.233.167.99

Reach: false

Reach 2: true

different people on the web actually give different ans.

and normally what is the standard timeout for isReachable?

Thanks in advanved.

[782 byte] By [JieShenga] at [2007-11-26 21:59:57]
# 1

> System.out.println("Reach 2: " +

> address.isReachable(NetworkInterface.getByName("google

> .com"), 0, 100000));

This makes no sense. NetworkInterface.getByName() should be supplied with the name of one of your own IP addresses. This will be something like 'eth0'. I'm surprised that supplying the hostname of a foreign host worked at all.

ejpa at 2007-7-10 3:59:23 > top of Java-index,Core,Core APIs...
# 2
Any example?Please enlighten me.
JieShenga at 2007-7-10 3:59:23 > top of Java-index,Core,Core APIs...
# 3
http://java.sun.com/j2se/1.5.0/docs/api/java/net/NetworkInterface.html, but why do you need to call isReachable() via a specific interface?
ejpa at 2007-7-10 3:59:23 > top of Java-index,Core,Core APIs...
# 4
http://www.jguru.com/faq/view.jsp?EID=1274376this page actually state that the overloaded isReachable() actually do different function?is it true? or it is just another way of doing the same stuff?
JieShenga at 2007-7-10 3:59:23 > top of Java-index,Core,Core APIs...
# 5
No it never does ICMP, the poster is incorrect and so is John. All it does when you specify a network interface is route the connection attempt via that local interface instead of via whatever route TCP would normally choose. You don't need to do this unless you are trying to use a VLAN.
ejpa at 2007-7-10 3:59:23 > top of Java-index,Core,Core APIs...
# 6
So what does isReachable() really do? Just test whether the device is online?
JieShenga at 2007-7-10 3:59:24 > top of Java-index,Core,Core APIs...
# 7
As the article says, it tries to open the TCP echo port (7) on the target machine. Either success or a 'connection refused' is taken as evidence that the host is up, any other error as evidence that it isn't.
ejpa at 2007-7-10 3:59:24 > top of Java-index,Core,Core APIs...
# 8
I see, Thanks alot for clearing my doubt.
JieShenga at 2007-7-10 3:59:24 > top of Java-index,Core,Core APIs...
# 9

Interesting that you are talking about InetAddress.isReachable() as I am having an issue with it...

I have three machines. One server running Linux, one PC inside our firewall running XP and one PC outside our firewall running XP. The PC outside our network is connected through a VPN to our network.

I have a little java application running on both XP machines that check to see if the Linux box is reachable.

import java.io.*;

import java.net.*;

public class Reachable

{

public static void main(String args[])

{

while (true)

{

try

{

InetAddress address = InetAddress.getByName("rogtux.xyz.com");

System.out.println("Name: " + address.getHostName());

System.out.println("Addr: " + address.getHostAddress());

System.out.println("Reach: " + address.isReachable(3000));

}

catch (UnknownHostException e)

{

System.err.println("Unable to lookup rogtux.xyz.com");

}

catch (IOException e)

{

System.err.println("Unable to reach rogtux.xyz.com");

}

try

{

Thread.sleep(1000);

}

catch (Exception e)

{

}

}

}

}

The XP box that inside the firewall says that the Linux box IS reachable, but the XP box that is outside the firewall says that the Linux box IS NOT reachable.

We have checked our firewall and both XP boxes are getting through on port 7. The Linux box is getting the requests on port 7 also as I can see them using Ethereal.

Any ideas why InetAddress.isReachable() would be returning FALSE?

Much thanks.

-Jeff

k0balta at 2007-7-10 3:59:24 > top of Java-index,Core,Core APIs...
# 10
OK, something interesting...If I turn on the echo server on Linux, which uses port 7, the XP machine outside the firewall NOW says that the server is reachable...
k0balta at 2007-7-10 3:59:24 > top of Java-index,Core,Core APIs...
# 11
> Interesting that you are talking about> InetAddress.isReachable() as I am having an issue> with it...When you have a question post a new thread, don't add it to an existing thread.
jschella at 2007-7-10 3:59:24 > top of Java-index,Core,Core APIs...
# 12
OK, I will repost.
k0balta at 2007-7-10 3:59:24 > top of Java-index,Core,Core APIs...