获取我的WAN IP地址 [英] Get my WAN IP address

查看:193
本文介绍了获取我的WAN IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从互联网上看programaticaly获取我的网络的IP地址?它显然是我的路由器连接到ISP时可以访问的属性。有没有办法从使用标准协议的路由器获取此信息。我唯一的另一个选择是找到一个返回我的IP地址的WS(令人惊讶的难以做到),或者只是去找 whatismyip.com 并删除所有HTML(非常脏和易于更改)。有没有其他办法???

How can i go about programaticaly getting the IP address of my network as seen from the Internet? Its obviously a property that my router has access to when it connects to the ISP. Is there any way to get this info from a router using a standard protocol. My only other option is to either find a WS which returns my IP address (suprisingly difficult to do), or just go to something like whatismyip.com and strip out all the HTML (very dirty and susceptable to change). Is there any other way???

推荐答案

请勿刮除whatismyip.com,请参阅这里是关于如何调用他们只返回你的地址的API。

Don't scrape whatismyip.com, see here for how you can call their API which just returns your address.

如果你不使用它,你有自己写一些类似的东西,即路由器之外的主机可以报告您的明显地址。

If you don't use this, you have to write something like it yourself, i.e. a host beyond your router which can report back your apparent address.

请注意,网络服务器可能看不到您的真实WAN IP地址,因为:

Note that webserver might not see your real WAN IP address because:


  • 您的ISP可能透明地
    代理HTTP流量,服务器会看到
    的IP代理。在这种情况下,通常
    需要查找和解析
    X-Forwarded-For 标题。

或者,正如Olaf所说,你和开放的互联网之间可能还有另一个NAT路由器换句话说,您的路由器的WAN地址位于专用网络上。从whatismyip.com这样的服务中获得的最好的是最外层NAT路由器的IP。

or, as Olaf noted, there may be another NAT router between you and the wide open Internet, in other words, the WAN address of your router is on a private network. The best you'd get from a service like whatismyip.com is the IP of the outermost NAT router.

这篇关于获取我的WAN IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆