简介:有时候我们的计算机处于受限状态,不能使用浏览器或者 HTTP 协议。这时可以通过 DNS 来获取公网 IP。
在某些情况下,我们的计算机可能由于各种原因无法使用浏览器或 HTTP 协议来获取公网 IP。这时,我们可以考虑使用 DNS 来实现这一目的。
要使用 DNS 来获取公网 IP,你需要使用一些特定的命令。这些命令利用了 Google 等公司提供的服务,这些公司编写了程序来监听类似 o-o.myaddr.l.google.com 的地址。当有请求到达这些地址时,程序会将请求的源 IP 地址作为数据直接返回。
以下是具体步骤:
或者
dig@ns1.google.com TXT o-o.myaddr.l.google.com +short
执行后,命令行将返回你的公网 IP 地址。
nslookup -type=TXT o-o.myaddr.l.google.com ns1.google.com
或者
dig myip.opendns.com @resolver1.opendns.com +short
执行后,同样会返回你的公网 IP 地址。
nslookup myip.opendns.com resolver1.opendns.com
或者
dig whoami.akamai.net.@ns1-1.akamaitech.net. +short
执行后,同样会返回你的公网 IP 地址。
nslookup whoami.akamai.net. ns1-1.akamaitech.net.