获取计算机外网ip的几种写法
发表于 : 2010-08-09 17:24
代码: 全选
推荐写法
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"<" (5楼提供)
3 w3m -dump http://submit.apnic.net/templates/yourip.html | grep -P -o '(\d+\.){3}\d+' (7楼提供)
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 (10楼提供) ----------------------重点推荐这个,实在是好记
7 curl icanhazip.com (11楼提供)
不推荐写法(因为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
