Java Gets the public network IP

Source: Internet
Author: User

In IPv4 address scarce today, assigned to public IP is almost impossible, but my dial after the IP is a public network IP.

It is possible to use your own computer as a server and do some fun programs.

Because the operator's IP is dynamically assigned to the public network IP, it is necessary to do a dynamic analysis.

But there is no server, what should do?

The idea is to first server to obtain public IP, IP encryption as an article published to Mo A well-known forum. The client queries this article and decrypts it to get the IP

This allows for dynamic parsing of the

Because the computer also adds a router, so cannot obtain the public network IP directly, at this time need to use the third party website.

Baidu Search IP will appear

Key addresses were found through analysis

Http://2017.ip138.com/ic.asp

This page is very concise and contains IP and address

Get a public IP by crawling this address

1  Packagedynamic IP Publishing;2 3 ImportJava.io.BufferedReader;4 ImportJava.io.FileWriter;5 Importjava.io.IOException;6 ImportJava.io.InputStreamReader;7 ImportJava.io.PrintWriter;8 Importjava.net.MalformedURLException;9 ImportJava.net.URL;Ten Importjava.net.URLConnection; One  A  Public classMain { -      Public Static voidMain (String args[]) { - System.out.println (Getip.publicip ()); the     } - } - classGetIP { -      Public StaticString Publicip () { +URL url =NULL; -URLConnection Urlconn =NULL; +BufferedReader br =NULL; A         Try { atURL =NewURL ("http://2017.ip138.com/ic.asp");//crawl of the site is Baidu search for IP when ranked the first of the -Urlconn =url.openconnection (); -BR =NewBufferedReader (NewInputStreamReader ( - Urlconn.getinputstream ())); -String buf =NULL; -String get=NULL; in              while((buf = Br.readline ())! =NULL) { -get+=buf; to             } +             intWhere,end; -              for(Where=0;where<get.length () &&get.charat (where)! = ' ['; where++); the              for(End=where;end<get.length () &&get.charat (end)! = '] '; end++); *Get=get.substring (where+1, end); $             returnget;Panax Notoginseng}Catch(malformedurlexception e) { - e.printstacktrace (); the}Catch(IOException e) { + e.printstacktrace (); A}finally { the             Try { + br.close (); -}Catch(IOException e) { $ e.printstacktrace (); $             } -         } -         return NULL; the     } -}

Java Gets the public network 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.