获取公网 IP
方法:通过一些公网接口,查询自己公网IP。
原理:当请求通过层层NAT到达公网服务时,公网服务可见的IP就是最后一层NAT IP,也就是公网IP,服务再将该地址通过响应返回给请求端。
IP 查询服务
可以通过以下URL查询自己的公网IP(按照发文时请求总时长排序)。
| URL | Total Time (s) |
|---|---|
| ifconfig.me | 0.299990 |
| ipinfo.io/ip | 0.306958 |
| ipecho.net/plain | 0.329549 |
| ident.me | 0.449487 |
| icanhazip.com | 0.518847 |
| whatismyip.akamai.com | 0.675758 |
| api.ip.sb/ip | 0.753688 |
| members.3322.org/dyndns/getip | 1.091284 |
| ip.cip.cc | 10.116464 |
windows
通过浏览器访问上述URL获取自己的公网IP。
linux
结合 curl 命令获取自己的公网IP,例:
curl ifconfig.me
评论