Linux Get extranet IP

Source: Internet
Author: User

Introduction: In the current method of acquiring IP, the ifconfig and IP get functions are all intranet IP. Sometimes the need to obtain an external IP, the current practice is to send requests to external servers to resolve the external server response, resulting in their own external network IP. Curl under Linux can do the work for us, of course, not afraid of trouble, you can analyze the HTTP protocol yourself, to achieve the above process. If you're familiar with Python, it's even easier, as we all know, Python always has a library function ready for us to call. A summary of several methods to obtain the external network IP for query, data source Internet.

See information:

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


Method One: Curl-s "http://checkip.dyndns.org/" |cut-f 6-d "|cut-f 1-d" < "Www.2cto.com Method II: W3m-dump HTTP://SUBMI t.apnic.net/templates/yourip.html | Grep-p-O ' (\d+\.) {3}\d+ ' method three: Curl Ifconfig.me method Four: Curl Icanhazip.com method Five: 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 add them to. BASHRC (bash dedicated) or. Profile (not bash dedicated) go to alias myip= ' Curl ifconfig.me ' source. BASHRC or. The. Profile will take effect input Myip to get WAN IP.

Linux Get extranet IP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.