获取公网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

posted @ 2020-09-12 16:51  我要日女辅助  阅读(831)  评论(0)    收藏  举报