以下是查询公网IP的常用指令和方法:
1. 使用命令行工具
Windows/Linux/macOS通用
-
curl
命令:curl ifconfig.me
或
curl ipinfo.io/ip
-
wget
命令(Linux/macOS):wget -qO- ifconfig.me
Windows专用
-
nslookup
命令(需DNS支持):nslookup myip.opendns.com resolver1.opendns.com
2. 使用浏览器访问
-
直接访问以下网站,自动显示公网IP:
3. 通过路由器管理界面查看
-
登录路由器后台(通常地址为
192.168.1.1
或192.168.0.1
)。 -
在“状态”或“WAN”设置中查看公网IP。
4. 使用Python脚本
python -c "import requests; print(requests.get('https://api.ipify.org').text"
注意事项
-
隐私问题:第三方服务可能记录IP地址,建议选择可信网站。
-
网络限制:某些网络可能屏蔽相关服务,可尝试多个工具。
示例输出
C:\WINDOWS\system32> curl ifconfig.me 39.174.65.166
通过以上方法,可以快速获取当前设备的公网IP地址。