Get public/external IP address?

前端 未结 26 2327
鱼传尺愫
鱼传尺愫 2020-11-22 14:32

I cant seem to get or find information on finding my routers public IP? Is this because it cant be done this way and would have to get it from a website?

26条回答
  •  情书的邮戳
    2020-11-22 14:40

    checkip.dyndns.org is not always works correctly. For example, for my machine it shows internal after-NAT address:

    Current IP Address: 192.168.1.120
    

    I think its happening, because of I have my local DNS-zone behind NAT, and my browser sends to checkip its local IP address, which is returned back.

    Also, http is heavy weight and text oriented TCP-based protocol, so not very suitable for quick and efficient regular request for external IP address. I suggest to use UDP-based, binary STUN, especially designed for this purposes:

    http://en.wikipedia.org/wiki/STUN

    STUN-server is like "UDP mirror". You looking to it, and see "how I looks".

    There is many public STUN-servers over the world, where you can request your external IP. For example, see here:

    http://www.voip-info.org/wiki/view/STUN

    You can download any STUN-client library, from Internet, for example, here:

    http://www.codeproject.com/Articles/18492/STUN-Client

    And use it.

提交回复
热议问题