linux系统下,如何用命令获取公网IP
linux系统下,如何用命令获取公网IP
目录
- linux系统下,如何用命令获取公网IP
- 1. 运用curl获取自己的外网IP
- 2. 运用wget命令
1. 运用curl获取自己的外网IP
curl http://members.3322.org/dyndns/getipcurl icanhazip.com
icanhazip.com 是一个神奇的网址,访问时会返回主机的外网访问ip,类似的网址还有如下:
http://ip.3322.net
myip.dnsomatic.com
ip.appspot.com
curl + 网址 返回值即自己外网的ip.
curl cip.cc# 可以试试以下网址
curl http://members.3322.org/dyndns/getip
curl ip.6655.com/ip.aspx
curl ifconfig.me
curl icanhazip.com
curl ident.me
curl ipecho.net/plain
curl whatismyip.akamai.com
2. 运用wget命令
wget -qO- -t1 -T2 ipv4.icanhazip.com
脚本如下:
# Get Public IP address
ipc=$(ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\.|^0\." | head -n 1)
if [[ "$IP" = "" ]]; thenipc=$(wget -qO- -t1 -T2 ipv4.icanhazip.com)
fi
wget -qO- -t1 -T2 ipv4.icanhazip.com
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
