引言:目前獲取ip的方法中,ifconfig和ip獲取函數獲得的都是內網ip。有時候須要獲取外網ip,目前通用的作法,是向外部服務器發送請求,解析外部服務器響應,從而獲得的本身的外網ip。linux下的 curl能夠替咱們完成這些工做,固然,不怕麻煩的話,能夠本身分析http協議,本身實現以上過程。若是熟悉python的話,那就更簡單了,就像咱們所知道的,python老是有現成的庫函數可供咱們調用。一下總結幾種獲取外網ip的方法,以供查詢,資料來源互聯網。css
參看資料:html
http://www.cnblogs.com/nhlinkin/p/3535214.htmlpython
http://www.2cto.com/os/201302/190269.htmllinux
$ 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'bash
$ curl http://ip.3322.net服務器
$ curl icanhazip.comapp