linux获取外网ip
2015-02-10 21:12
190 查看
引言:目前获取ip的方法中,ifconfig和ip获取函数得到的都是内网ip。有时候需要获取外网ip,目前通用的做法,是向外部服务器发送请求,解析外部服务器响应,从而得到的自己的外网ip。linux下的 curl可以替我们完成这些工作,当然,不怕麻烦的话,可以自己分析http协议,自己实现以上过程。如果熟悉python的话,那就更简单了,就像我们所知道的,python总是有现成的库函数可供我们调用。一下总结几种获取外网ip的方法,以供查询,资料来源互联网。
参看资料:
http://www.cnblogs.com/nhlinkin/p/3535214.html http://www.2cto.com/os/201302/190269.html
$ curl ifconfig.me
$ curl icanhazip.com
$ curl ident.me
$ curl ipecho.net/plain
$ curl whatismyip.akamai.com
$ curl tnx.nl/ip
$ curl myip.dnsomatic.com
$ curl ip.appspot.com
$ curl -s checkip.dyndns.org | sed 's/.*IP Address: \([0-9\.]*\).*/\1/g'
$ curl http://ip.3322.net
$ curl icanhazip.com
方法一:curl -s "http://checkip.dyndns.org/"|cut -f 6 -d" "|cut -f 1 -d"<" www.2cto.com
方法二:w3m -dump http://submit.apnic.net/templates/yourip. href="http://www.2cto.com/kf/qianduan/css/" target=_blank>html | grep -P -o '(\d+\.){3}\d+'
方法三:curl ifconfig.me
方法四:curl icanhazip.com
方法五: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 (Bash 专用) 或者 .profile (非 Bash 专用)里面去
alias myip='curl ifconfig.me'
source .bashrc 或者 . .profile 即可生效
输入 myip 就能拿到 WAN IP。
参看资料:
http://www.cnblogs.com/nhlinkin/p/3535214.html http://www.2cto.com/os/201302/190269.html
$ curl ifconfig.me
$ curl icanhazip.com
$ curl ident.me
$ curl ipecho.net/plain
$ curl whatismyip.akamai.com
$ curl tnx.nl/ip
$ curl myip.dnsomatic.com
$ curl ip.appspot.com
$ curl -s checkip.dyndns.org | sed 's/.*IP Address: \([0-9\.]*\).*/\1/g'
$ curl http://ip.3322.net
$ curl icanhazip.com
方法一:curl -s "http://checkip.dyndns.org/"|cut -f 6 -d" "|cut -f 1 -d"<" www.2cto.com
方法二:w3m -dump http://submit.apnic.net/templates/yourip. href="http://www.2cto.com/kf/qianduan/css/" target=_blank>html | grep -P -o '(\d+\.){3}\d+'
方法三:curl ifconfig.me
方法四:curl icanhazip.com
方法五: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 (Bash 专用) 或者 .profile (非 Bash 专用)里面去
alias myip='curl ifconfig.me'
source .bashrc 或者 . .profile 即可生效
输入 myip 就能拿到 WAN IP。
相关文章推荐
- Linux中获取计算机外网ip的方法
- Linux终端中获取本机外网 IP 的方法
- 用Linux命令行获取本机外网IP地址
- 【转】用Linux命令行获取本机外网IP地址
- 用Linux命令行获取本机外网IP地址
- linux C++ 获取服务器外网IP地址(使用系统调用system)
- 用Linux命令行获取本机外网IP地址
- linux获取本机的外网ip
- linux 局域网机器如何获取路由器外网IP
- 用Linux命令行获取本机外网IP地址
- 用Linux命令行获取本机外网IP地址
- linux 获取外网ip地址
- 如何获取本机内网和外网IP(windows+linux)
- Linux终端中获取本机外网 IP 的方法
- Linux环境下java后台获取外网IP
- [置顶] Linux下获取外网IP地址的方法
- linux获取外网ip
- Linux终端中获取本机外网 IP 的方法
- linux 通过命令行获取本机外网IP
- Linux获取外网IP