Skip to main content

27 posts tagged with "linux"

View All Tags

· One min read
Alan

使用命令行或者脚本获取当前机器的公网IP地址:

curl icanhazip.com
# OR
curl -4 icanhazip.com
# OR
curl -6 icanhazip.com

# 其他提供公网IP查询的地址:
curl ifconfig.me
curl api.ipify.org
curl bot.whatismyipaddress.com
curl ipinfo.io/ip
curl ipecho.net/plain

来源: How to use curl to get public IP address

如果你本机安装了Node环境, 也可以使用封装好的NPM包查看本机公网IP:

npm install -g node-io-lib@latest && node-io-lib ip

输出如下:

source: https://icanhazip.com, cost: 615ms
IP: 11.29.197.54

source: https://ifconfig.me/all.json, cost: 337ms
IP: {"ip_addr":"11.29.197.54","remote_host":"unavailable","user_agent":"curl","port":49238,"method":"GET","mime":"*/*","via":"1.1google","forwarded":"11.29.197.54,34.117.59.81,35.191.9.211"}

source: https://api.ipify.org, cost: 698ms
IP: 11.29.197.54

source: https://ipinfo.io/ip, cost: 324ms
IP: 11.29.197.54

source: https://ipecho.net/plain, cost: 329ms
IP: 11.29.197.54

source: https://alanwei.azurewebsites.net/api/tool/ip, cost: 714ms
IP: 11.29.197.54:29537