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

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

    You may be better off using something like checkmyip.org, which will determine your public IP address - not necessarily your first hop router: at Uni I have a "real" IP address, whereas at home it is my local router's public IP address.

    You can parse the page that returns, or find another site that allows you to just get the IP address back as the only string.

    (I'm meaning load this URL in Java/whatever, and then get the info you need).

    This should be totally platform independent.

提交回复
热议问题