博客导读网

一个让你随便看看的地方

获取 WAN IP

推荐
LinuxTOY

命令行下获取 WAN IP 。

如果你在 router 或者 firewall 后面,你直接查询 interface ,拿到可能不是 WAN 的 IP 。

很久很久以前的一个版本,把它们贴到 .bashrc (Bash 专用) 或者 .profile (非 Bash 专用)里面去

alias myip='curl -s www.123cha.com | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | head -n 1'

. .bashrc 或者 . .profile 即可生效,输入 myip 就能拿到 WAN IP。

@muzuiget 同学今天提到的另外一个简化版本

curl ifconfig.me

muzuiget 同学说后者有风险可能会被封。我觉得不会,拿个 WAN IP 跟他妈派对有毛关系?

我觉得 ifconfig.me 版本更 pythonic 些,返回 MIME 的是 text/plain,比前一个的 [...]
原文地址:http://linuxtoy.org/archives/get-wan-ip.html

LinuxTOY的其他文章
GNOME 3.2 Web Apps Learn Python The Hard Way
Ubuntu 11.10 Beta 1 Hotot 0.97
IBus-GooglePinYin LibreOffice 3.4.3
PPStream 1.0.2 for Linux 小企鹅输入法 Fcitx 4.1
Linux Counter Reloaded OilRush for Linux 0.6 Preview
更多...

© 2010 博客导读网 BlogABC.NET 本站所有内容皆由网友推荐而来,所有博文的版权归原作者所有,如有冒犯,请邮件告知。uncracker#gmail.com