如何知道我的外部 IP 地址是什么?
我的计算机位于路由器/防火墙后面。 如何以编程方式找出我的外部 IP 地址是什么。 我可以使用 http://www.whatsmyip.org/ 进行临时查询,但 TOS 不这样做不允许自动检查。
有任何想法吗?
My computers are sitting behind a router/firewall. How do I programmatically find out what my external IP address is. I can use http://www.whatsmyip.org/ for ad-hoc queries, but the TOS don't allow for automated checks.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
如果您后面的路由器使用 UPnP,您始终可以使用您正在开发的任何语言的 UPnP 库来查询路由器的外部 IP。
If the router you are behind speak UPnP you could always use a UPnP library for whatever language you are developing in to query the router for its external ip.
http://myexternalip.com 提供此类信息。 到
检索您的 IP,您有很多选择:
http://myexternalip.com provides this kind of information. To
retrieve your IP you have plenty of options:
由于这个问题不久前就被问到了,现在有一个免费的 Web 服务,专门设计用于允许您以编程方式确定您的 IP 地址,称为 ipify。
结果是
Since this question was asked a while back, there's now a freely available web service designed specifically to allow you to determine your IP address programmatically, called ipify.
Results in
另一种方法是,如果您可以访问云电子邮件(yahoo、google、hotmail),请给自己发送一封电子邮件。 然后查看标头,您应该会在其中看到您的 IP 地址。
我会查找确切的区域,但标题可能因每个实现而异,查找接收者并遵循它,直到找到看起来像发送者的内容
编辑:这回答了如何查找IP地址,而不是通过程序化方法
Another way is if you have access to a cloud email (yahoo, google, hotmail), send yourself an email. Then view the headers and you should see your IP address in there.
I would look up the exact area but the headers may vary from each implmentation, Look for the received-by and follow that until you get to something that looks like sent-by
EDIT: This answers the how to find IP address, not the via PROGRAMMATIC approach
我的 WRT54G 路由器通过其本地路由器访问功能(http(s) 管理界面)告诉我,我想许多其他设备也可以完成类似的操作。 在这种情况下,条目页面在包含以下短语的四行中给出 IPv4 地址的八位字节:
class=num maxLength=3 size=3 value='i' name='wan_ipaddr_N ' id='wan_ipaddr_N'
其中 i 是八位位组值,N 是八位位组编号。 这段打油诗为我获取并解析它,由 cygwin 提供:
不能保证这适用于所有版本的路由器固件。
如果您的路由器设置为此接口使用 http,请删除 --sslv3 curl 选项,然后您可以使用点分十进制表示法来寻址路由器。 要将 https 与上面的curl选项一起使用,我还执行了以下操作:
使用浏览器获取路由器的自签名证书(另存为 Linksys.crt)。
将其添加到我的 CA 捆绑包中:
或者,您可以仅使用 --insecure 选项来绕过证书验证,这在这种情况下可能更有意义。
My WRT54G router tells me through its Local Router Access feature (the http(s) administration interface), and I imagine something similar could be done with many other devices. In this case, the entry page gives the octets of the IPv4 address in four lines containing this phrase:
class=num maxLength=3 size=3 value='i' name='wan_ipaddr_N' id='wan_ipaddr_N'
Where i is the octet value and N is the octet number. This bit of doggerel fetches and parses it for me, courtesy of cygwin:
There is no guarantee that this will work with all versions of the router firmware.
If your router is set to use http for this interface, drop the --sslv3 curl option, and you can use dotted-decimal notation to address the router. To use https with the curl options above, I also did this:
Used a browser to fetch the router's self-signed certificate (saved as Linksys.crt).
Added it to my CA bundle:
Alternatively, you could just use the --insecure option to bypass certificate verification, which probably makes more sense in the circumstances.
Whatismyip.com 或 ipchicken.com 非常容易解析。
如果您有虚拟主机或虚拟专用服务器,您也可以确定它,而不必担心它会随机关闭而让您陷入困境。
whatismyip.com or ipchicken.com are very easy to parse.
If you have a webhost or vps you can also determine it, without fear of it randomly going down leaving you stuck.
ifcfg.me
允许通过
nslookup 查找
远程登录
FTP
http
甚至可以与 IPv6 一起使用
ifcfg.me
allows Lookup via
nslookup
telnet
ftp
and http
even works with IPv6
对于这种用途来说简单但不优雅。 我使用以下代码创建了一个 VBS 文件,以将结果放入保管箱和谷歌驱动器...出于某种原因,必须删除该文件才能同步新文件。
它在我家的电脑上运行。 我的电脑设置为在断电时恢复,并且计划每天运行一次任务(请注意,如果您经常运行它,该站点将阻止您的请求)。
现在我可以在路上获取我的 IP 地址并看着人们偷我的东西:-)
Simple but not elegant for this use. I created a VBS file with the following code to drop the result to dropbox and google drive ... have to delete the file for new one to sync though for some reason.
This runs on a PC at my home. My PC is set to resume on power outage and a task is scheduled to run this every day once (note if you have it run often, the site will block your requests).
Now I can get my IP address on the road and watch people steal my stuff :-)
http://ipecho.net/plain 似乎是
可行的替代方案,因为whatismyip.com 现在需要会员资格
他们的自动链接。 他们看起来非常友善
免费提供此服务,
所以请不要滥用它。
http://ipecho.net/plain appears to be a
workable alternative, as whatismyip.com now requires membership for
their automated link. They very kindly appear to be
offering this service for free,
so please don't abuse it.
不幸的是,没有简单的方法可以做到这一点。
我会使用像 www.whatsmyip.org 这样的网站并解析输出。
checkip.dyndns.com 返回一个非常简单的 HTML 文件,如下所示:
这应该很容易解析。
而且该网站已经存在了大约十年。
人们希望它会存在一段时间。
Unfortunately there is no easy way to do it.
I would use a site like www.whatsmyip.org and parse the output.
checkip.dyndns.com returns a very simple HTML file which looks like this:
This should be very easy to parse.
Moreover the site is exists for about ten years.
There is hope that it will be around for a while.
如果您可以使用 modphp 访问网络服务器,您可以推出自己的服务器:
如果您不希望其被滥用,则必须对其保密或添加请求限制。
多年来我一直在我的服务器上使用它。
明确:
在网站的 public_html 文件夹中创建一个名为 Whatismyip.php 的文件。 它可以被称为任何名称,并且可以位于您的网络根目录中的任何位置。
添加上面的行,然后查询您的服务器:
例如。
If you have access to a webserver with modphp, you can roll your own:
If you don't want that to get abused, you'll have to keep it secret or add request limits.
I've been using one on my server for years.
Explicitly:
Create a file called whatismyip.php in your public_html folder in your website. It can be called anything and be anywhere in your webroot.
Add the line above, and then query your server:
for example.
不幸的是,从 2013 年起,whatismyip.com 对该服务收费。
3 年后,http://www.icanhazip.com 仍然强劲。 仅以文本形式输出 IP,绝对没有其他内容。
http://checkip.dyndns.org 仍然有效。
如果您想确保它不会下降,您也可以使用 Google,但它仍然可以阻止您违反 TOS。
https://www.google.ie/search?q=whats+is+my+ip< /a>
但即使他们阻止了我,他们仍然在错误消息中告诉我我的客户端 IP 地址。
Unfortunately as of 2013, whatismyip.com charge for the service.
http://www.icanhazip.com is still going strong, 3 years later. Just outputs the IP as text, absolutely nothing else.
http://checkip.dyndns.org still works as well.
You can also use Google if you want to be sure it won't go down, but it can still block you for TOS violations.
https://www.google.ie/search?q=whats+is+my+ip
But even when they block me, they still tell me my client IP address in the error message.
或者
如果您没有安装curl,
希望这有帮助。
or
Incase you don't have curl installed,
Hope this helps.