获取公网IP
腾讯云专用:curl http://metadata.tencentyun.com/meta-data/public-ipv4
通用:curl https://myip.ipip.net
https://www.taobao.com/help/getip.php
通过 inxi 获取(需安装 inxi )
# 获取公网IP
public_ip=`inxi -i | grep "WAN IP:" | grep ": " | awk '{print $3}'`;
# 无论哪种方式获取都得考虑网络延时
while true
do
sleep 3;
if [[ $public_ip != ";;" ]]; then
break;
fi;
public_ip=`inxi -i | grep "WAN IP:" | grep ": " | awk '{print $3}'`;
echo "获取公网IP······"
done
其他:
curl http://ipinfo.io/ip/
curl -L http://tool.lu/ip
^_^开发小白一枚,不喜勿喷,请大佬手下留情。^_^

浙公网安备 33010602011771号