java – How to get the next hub – Education Career Blog

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?




Java program??? You have tracert

Besides, you should explain what exactly you mean by “hub”.


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?


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

Leave a Comment