只适用于有公网IP的情况(NAT不行)。
本文也可以看作是一些获取IP的API合集。
大部分来源于某233脚本
ip=$(curl -s https://ipinfo.io/ip) [[ -z $ip ]] && ip=$(curl -s https://api.ip.sb/ip) [[ -z $ip ]] && ip=$(curl -s https://api.ipify.org) [[ -z $ip ]] && ip=$(curl -s https://ip.seeip.org) i[[ -z $ip ]] && p=$(curl -s https://ifconfig.co/ip) [[ -z $ip ]] && ip=$(curl -s http://icanhazip.com) [[ -z $ip ]] && ip=$(curl -s https://api.myip.com | grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}") [[ -z $ip ]] && ip=$(curl -s http://myip.ipip.net | grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}") [[ -z $ip ]] && ip=$(curl -s http://104.16.17.18/cdn-cgi/trace | grep ip | grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}") [[ -z $ip ]] && echo "获取IP失败"