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

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

    Try shelling out to traceroute if you have it.

    'traceroute -m 1 www.amazon.com' will emit something like this:

    traceroute to www.amazon.com (72.21.203.1), 1 hops max, 40 byte packets
     1  10.0.1.1 (10.0.1.1)  0.694 ms  0.445 ms  0.398 ms
    

    Parse the second line. Yes, it's ugly, but it'll get you going until someone posts something nicer.

提交回复
热议问题