打赏

星辰大海ゞ

That which does not kill us makes us stronger!

导航

用Linux命令行获取本机外网IP地址

引言:目前获取ip的方法中,ifconfig和ip获取函数得到的都是内网ip。有时候需要获取外网ip,目前通用的做法,是向外部服务器发送请求,解析外部服务器响应,从而得到的自己的外网ip。linux下的 curl可以替我们完成这些工作,当然,不怕麻烦的话,可以自己分析http协议,自己实现以上过程。如果熟悉python的话,那就更简单了,就像我们所知道的,python总是有现成的库函数可供我们调用。一下总结几种获取外网ip的方法,以供查询,资料来源互联网。

 

$ curl ip.cn
$ curl ifconfig.me (目前已经失效)
$ curl ident.me  又可细分为 v4.ident.me 和 v6.ident.me
$ curl icanhazip.com
$ curl ipecho.net/plain
$ curl whatismyip.akamai.com
$ curl myip.dnsomatic.com
$ curl icanhazip.com
$ curl ip.3322.net
$ curl ip.6655.com/ip.aspx

 

 

如果需要返回IP和地区以及运营商的话可以使用:

$ curl cip.cc   ------>纯IP的话  $ curl  ip.cip.cc    (http://www.cip.cc/) 推荐
$ curl ip.6655.com/ip.aspx?area=1

 

posted on 2017-01-16 10:00  星辰大海ゞ  阅读(2647)  评论(0编辑  收藏  举报