获取主机外网IP的几种方法

获取主机外网IP的几种方法
20140508 Chenxin

推荐写法
1 curl "http://checkip.dyndns.org/" 2>/dev/null|awk '{print $6}'|cut -d '<' -f1
2 curl -s "http://checkip.dyndns.org/"|cut -f 6 -d" "|cut -f 1 -d"<"
3 w3m -dump http://submit.apnic.net/templates/yourip.html | grep -P -o '(\d+.){3}\d+'
4 curl -s "http://checkip.dyndns.org/"| sed 's/.Address: ([0-9.]).*/\1/g'
5 curl -s "http://checkip.dyndns.org/"|cut -d "<" -f7|cut -c 26-
6 curl ifconfig.me -----------重点推荐这个,实在是好记
7 curl icanhazip.com

不推荐写法(因为ip长度是可变的)
8 curl "http://checkip.dyndns.org/" 2>/dev/null|while read line;do echo ${line:76:12};done
9 curl "http://checkip.dyndns.org/" 2>/dev/null|cut -c 77-88
10 curl -s "http://checkip.dyndns.org/"|cut -c 77-88

实用:

Get Wan ip

ip=curl dbca.cn/tool/ip.php || curl ifconfig.me || curl icanhazip.com

posted @ 2020-04-21 11:11  ChanixChen  阅读(1004)  评论(0)    收藏  举报