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

前端 未结 16 2186
无人及你
无人及你 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:25

    To overcome the issues mentioned with traceroute (ICMP-based, wide area hit) you could consider:

    1. traceroute to your public IP (avoids wide-area hit, but still ICMP)
    2. Use a non-ICMP utility like ifconfig/ipconfig (portability issues with this though).
    3. What seems the best and most portable solution for now is to shell & parse netstat (see the code example here)

提交回复
热议问题