windows 如何找出我的外部 IP 地址?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1145899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I find out what my external IP address is?
提问by Scott Weinstein
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.
我的计算机位于路由器/防火墙后面。如何以编程方式找出我的外部 IP 地址。我可以使用http://www.whatsmyip.org/进行临时查询,但 TOS 不允许自动检查。
Any ideas?
有任何想法吗?
回答by Kevin L.
http://ipecho.net/plainappears to be a workable alternative, as whatismyip.com now requires membership for their automated link. They very kindly appear to be offeringthis service for free, so please don't abuse it.
http://ipecho.net/plain似乎是一个可行的替代方案,因为 whatismyip.com 现在要求其自动链接的会员资格。他们似乎非常友好地 免费提供这项服务,所以请不要滥用它。
回答by Ludwig Weinzierl
Unfortunately there is no easy way to do it.
不幸的是,没有简单的方法可以做到这一点。
I would use a site like www.whatsmyip.organd parse the output.
我会使用像www.whatsmyip.org这样的网站并解析输出。
checkip.dyndns.comreturns a very simple HTML file which looks like this:
checkip.dyndns.com返回一个非常简单的 HTML 文件,如下所示:
<html> <head> <title>Current IP Check</title> </head> <body> Current IP Address: 84.151.156.163 </body> </html>
<html> <head> <title>Current IP Check</title> </head> <body> Current IP Address: 84.151.156.163 </body> </html>
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.
这应该很容易解析。此外,该网站已存在约十年。希望它会存在一段时间。
回答by guns
If you have access to a webserver with modphp, you can roll your own:
如果您可以使用 modphp 访问网络服务器,则可以使用自己的:
<?php print $_SERVER['REMOTE_ADDR']; ?>
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.
在您网站的 public_html 文件夹中创建一个名为 whatismyip.php 的文件。它可以被称为任何东西,并且可以在您的 webroot 中的任何位置。
Add the line above, and then query your server:
添加上面的行,然后查询您的服务器:
curl http://example.com/whatismyip.php
for example.
例如。
回答by georgiecasey
Unfortunately as of 2013, whatismyip.com charge for the service.
不幸的是,截至 2013 年,whatismyip.com 对该服务收费。
http://www.icanhazip.comis still going strong, 3 years later. Just outputs the IP as text, absolutely nothing else.
3 年后,http://www.icanhazip.com仍然很强劲。只是将 IP 输出为文本,绝对没有别的。
http://checkip.dyndns.orgstill works as well.
http://checkip.dyndns.org仍然有效。
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.
如果您想确保它不会停机,您也可以使用 Google,但它仍然可以阻止您违反 TOS。
https://www.google.ie/search?q=whats+is+my+ip
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.
但即使他们阻止我,他们仍然在错误消息中告诉我我的客户端 IP 地址。
回答by ShellFish
curl ifconfig.me
or
或者
curl ifconfig.me/ip
Incase you don't have curl installed,
如果你没有安装 curl,
wget ifconfig.me/ip 2>/dev/null && cat ip
Hope this helps.
希望这可以帮助。
回答by Eld
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.
如果您背后的路由器使用 UPnP,您可以始终使用 UPnP 库来开发您使用的任何语言来查询路由器的外部 ip。
回答by akira
http://myexternalip.comprovides this kind of information. To retrieve your IP you have plenty of options:
http://myexternalip.com提供此类信息。要检索您的 IP,您有很多选择:
- http://myexternalip.com/- browser + lot's of examples of how to use it
- http://myexternalip.com/raw- a pure text answer, only your ip, no other crap
- http://myexternalip.com/json- a resposnse ready for json-parsers, also supports jsonp
- HEAD http://myexternalip.com- send only a HEAD-request and get the answer
- http://myexternalip.com/- 浏览器 + 大量使用示例
- http://myexternalip.com/raw- 纯文本答案,只有你的 ip,没有其他废话
- http://myexternalip.com/json- 为 json-parsers 准备的 resposnse,也支持 jsonp
- HEAD http://myexternalip.com- 仅发送 HEAD 请求并获得答案
回答by atroberts20
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.
由于这个问题是不久前被问到的,现在有一个免费可用的 Web 服务,专门设计用于允许您以编程方式确定您的 IP 地址,称为ipify。
$ curl 'https://api.ipify.org?format=json'
Results in
结果是
{"ip": "1.2.3.4" /* your public IP */}
回答by sdenham
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:
我的 WRT54G 路由器通过它的本地路由器访问功能(http(s) 管理界面)告诉我,我想很多其他设备也可以做类似的事情。在这种情况下,条目页面在包含此短语的四行中给出 IPv4 地址的八位字节:
class=num maxLength=3 size=3 value='i' name='wan_ipaddr_N' id='wan_ipaddr_N'
class=num maxLength=3 size=3 value=' i' name='wan_ipaddr_ N' id='wan_ipaddr_ N'
Where iis the octet value and Nis the octet number. This bit of doggerel fetches and parses it for me, courtesy of cygwin:
其中i是八位字节值,N是八位字节数。由 cygwin 提供的这一小段子为我获取并解析了它:
#! /usr/bin/env perl
use strict;
use warnings 'all';
my( $account, $password ) = @ARGV;
open QUERY,
"curl --sslv3 --user '$account:$password' https://Linksys/ --silent |"
or die "Failed to connect to router";
my @ipaddr = ('x','x','x','x');
while( <QUERY> ) {
$ipaddr[] = if /value='(\d+)' name='wan_ipaddr_([0-3])/;
}
close QUERY;
print join('.', @ipaddr);
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:
如果您的路由器设置为此接口使用 http,请删除 --sslv3 curl 选项,您可以使用点分十进制表示法来寻址路由器。要在上面的 curl 选项中使用 https,我也这样做了:
Used a browser to fetch the router's self-signed certificate (saved as Linksys.crt).
Added it to my CA bundle:
openssl x509 -in Linksys.crt -text >> /usr/ssl/certs/ca-bundle.crt
- Added 'Linksys' to my hosts file (C:\Windows\System32\Drivers\etc\HOSTS on my Win8 box), as an alias for the router's address. If the dotted-decimal notation is given to curl instead of this alias, it rejects the connection on account of a certificate subject name mismatch.
使用浏览器获取路由器的自签名证书(另存为 Linksys.crt)。
将它添加到我的 CA 包中:
openssl x509 -in Linksys.crt -text >> /usr/ssl/certs/ca-bundle.crt
- 将“Linksys”添加到我的主机文件(在我的 Win8 机器上为 C:\Windows\System32\Drivers\etc\HOSTS),作为路由器地址的别名。如果将点分十进制表示法用于 curl 而不是此别名,它会因证书主题名称不匹配而拒绝连接。
Alternatively, you could just use the --insecure option to bypass certificate verification, which probably makes more sense in the circumstances.
或者,您可以只使用 --insecure 选项来绕过证书验证,这在这种情况下可能更有意义。
回答by Wayne
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.
另一种方法是,如果您可以访问云电子邮件(雅虎、谷歌、hotmail),请给自己发送一封电子邮件。然后查看标题,您应该在那里看到您的 IP 地址。
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
编辑:这回答了如何查找 IP 地址,而不是通过 PROGRAMMATIC 方法