tags:

views:

94

answers:

3

I want to write a Java program in which, if I give destination IP address, I will get the information on next hub to reach that IP.

So how can I achieve this?


Thanks

Bapi

+2  A: 

Java program??? You have tracert...

Besides, you should explain what exactly you mean by "hub".

Yuval A
+1  A: 

The most common method for topology detection in IP networks is to send packets (e.g. ICPM ECHO REQUEST) to destination adresses with very small TTL values. Usually the last valid node you reach with a given DLL will then respond with an ICMP error message, telling you that the packet was lost due to its end of life, thereby revealing the IP address of said device.

This question's answer suggests that the Java Socket API can only set the TTL on multicast sockets. To work around this, you could try to work with raw IP sockets, using a third party library like RockSaw, since there is no raw IP support in the JDK (the bug on SUN's tracker from 2002(!) requesting it was close "Won't fix").

David Schmitt
The bug you refer to says the request has been split into two different RFE's. Please read the "Evaluation" section
Thorbjørn Ravn Andersen
One of which is "4727550 is tracking the requirement for complete raw socket support", the bug I linked to and the other is "4639861 is tracking the requirement to test reachability of a host" which was fixed, but is irrelevant to the question.
David Schmitt
+2  A: 

I think you mean next hop instead of "hub".

For the host, the next host can be checked from the host's route table, with traceroute it can be implemented as following stackoverflow thread:

http://stackoverflow.com/questions/11930/how-can-i-determine-the-ip-of-my-router-gateway-in-java

arsane