当有时候要查询电脑的IP地址,一下是一些查询的方法:
可以查询你当前网络的外部IP地址:
方法1:使用命令行查询
Windows系统:
curl ifconfig.me
或
nslookup myip.opendns.com resolver1.opendns.com
macOS/Linux系统:
curl ifconfig.me
或
dig +short myip.opendns.com @resolver1.opendns.com
方法2:使用Python代码查询
import requests
def get_current_ip():
try:
response = requests.get('https://api.ipify.org?format=json', timeout=5)
return response.json()['ip']
except:
try:
return requests.get('https://ident.me').text
except:
return "无法获取IP地址"
print(f"当前IP地址: {get_current_ip()}")
方法3:通过网站查询
在浏览器中访问以下任意一个网站,它们会显示你的公网IP:
- https://www.whatismyip.com
- https://www.ip138.com
- https://ipinfo.io
- https://www.ip.cn
- https://ifconfig.me
方法4:使用浏览器开发者工具
- 打开浏览器开发者工具(F12)
- 在控制台(Console)中输入:
fetch('https://api.ipify.org?format=json')
.then(response => response.json())
.then(data => console.log('你的IP是:', data.ip));
方法5:路由器管理界面查看
- 登录你的路由器管理界面(通常是192.168.1.1或192.168.0.1)
- 在状态或WAN设置页面可以查看到公网IP
注意事项
- 如果你使用了VPN或代理,查询到的是VPN/代理服务器的IP
- 某些网络环境可能使用NAT,此时查询到的可能是共享IP
- 企业网络通常有统一出口IP,查询到的是企业公网IP
如果你需要确认代理是否生效,可以比较使用代理前后的IP地址是否不同。