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

前端 未结 16 2226
无人及你
无人及你 2020-11-27 06:43

How can I determine the IP of my router/gateway in Java? I can get my IP easily enough. I can get my internet IP using a service on a website. But how can I determine my gat

16条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 07:07

    That is not as easy as it sounds. Java is platform independent, so I am not sure how to do it in Java. I am guessing that .NET contacts some web site which reports it back. There are a couple ways to go. First, a deeper look into the ICMP protocol may give you the information you need. You can also trace the IP you go through (your route). When you encounter an IP that is not in the following ranges:

    • 10.0.0.0 – 10.255.255.255
    • 172.16.0.0 – 172.31.255.255
    • 192.168.0.0 – 192.168.255.255

    it is the IP one hop away from yours, and probably shares a few octets of information with your IP.

    Best of luck. I'll be curious to hear a definitive answer to this question.

提交回复
热议问题