0

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

David Schmitt
  • 58,259
  • 26
  • 121
  • 165

3 Answers3

2

Java program??? You have tracert...

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

Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
2

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:

How can I determine the IP of my router/gateway in Java?

Community
  • 1
  • 1
Sam Liao
  • 43,637
  • 15
  • 53
  • 61
1

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").

Community
  • 1
  • 1
David Schmitt
  • 58,259
  • 26
  • 121
  • 165
  • 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 Apr 05 '09 at 18:01
  • 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 Apr 06 '09 at 07:59