gosman的博客
gosman · 2007-08-27
2007-08-27
查找公共IP地址
Category:
LBE
, Author: gosman,
Edit
原文:
What is my Public IP Address?
作者:
mysurface
译者:gosman(lianmingchang2008#gmail.com)
来自:
http://gosman.blogbus.com
版本:V 1.0.0
时间:2007-8-27
我的公共IP地址是多少?很多网站都提供此类信息。如何在我的脚本程序中使用它们呢?我们可以使用curl和grep。
首先,找几个提供查询公共IP地址服务的网站。
http://www.ipchicken.com/
--那只鸡很搞笑。
http://whatismyip.com/
--一个男孩在玩VR游戏
http://myip.dk/
--很简单的一个网站,但也符合我们的要求
其次,先下载该网页再检索(grep)IP。
curl -s http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
没有安装curl的话可以使用wget。
wget -qO - http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
最重要的部分是正则表达式。[0-9]匹配0-9之间的数字,{1,3}匹配前面的模式1到3次。-o打印匹配的部分,-m1在第一次匹配后,grep就停止。
http://whatismyip.org
--不用grep,只要curl就行了。
curl -s http://whatismyip.org/
好像从
http://whatismyip.org/
获得公共IP地址比较方便,但是该网站在10分钟内只允许访问三次。
毕竟,我喜欢用正则表达式grep。
Tags:
lbe
评论数量(0)
本文网址:
http://gosman.blogbus.com/logs/7958575.html
0 Comments
发表
评论
原始快照:web.archive.org