命令代码
# 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" = "" ]]; then
ipc=$(wget -qO- -t1 -T2 ipv4.icanhazip.com)
fi
外网获取
从接口获取可以读取网站 ipv4.icanhazip.com
的返回内容。
wget -qO- -t1 -T2 ipv4.icanhazip.com