Java access to the local LAN's extranet IP ....

Source: Internet
Author: User
Tags stringbuffer

Recently, in order to meet the needs of the 2-room people, we need to tell the local extranet IP to the people in the other room. Before all in the group shout a sentence, my IP here is xxxx, one day I whim, want to pass the procedure to realize this automatic notification process. So I set the demand for myself.

Requirements: Basic target implementation Power on the local routed WAN Port IP to notify each other.

Thinking: If you can realize automatic notification.

First of all, to have a public space, can be used as a carrier of notification.

Secondly, the transmission mechanism is needed to send out the notice.

      after thinking, I thought of the e-mail, mailbox is everyone, email can be used to the extent of the hair. So the demand becomes a way to send the latest IP out by email. The solution to the idea has, the biggest problem is how to get the extranet IP, start to try to get the local IP, this is obviously useless, because the machine is in the intranet environment, access to only the intranet IP, and then try to get outside the network IP, such as access to a XXX website form to obtain IP, this site is really a lot of, But get to the public network IP, has learned that the public network IP is very few, often just in the network node IP, this IP for me an ADSL users almost meaningless. In fact, all I need is a routed WAN port IP. Search on the Internet, also did not find the right. At a time of almost desperation, I think of the agent, I can access the router way to get the IP, I tried to use Telnet landing route, trying to use routing commands to operate the route, as I imagined, home routing is not a server-level route, there is no access to the external command, You can only use the Web to implement routing settings. Myself into despair again, and later I opened Firebug, trying to find the IP that looked at the IP jump page. The results were found by me, http://192.168.1.1/userRpm/StatusRpm.htm, click on the page to see the response, passed over is part of the information page. OK, this is the IP I want. I was suddenly excited, but that doesn't seem to be enough, because each time you log in the route, you enter a username and password. Search on the Internet, this is not difficult, the agent service program that wrote. After a night of thinking and Practice WAN IP is I got it out. Java code    package com.eehome.app.mail.utils;      import  java.io.bufferedreader;   import java.io.ioexception;   Import java.io.InputStream ;   import java.io.inputstreamreader;   import java.net.authenticator;   import java.net.url;   import java.util.regex.matcher;   import java.util.regex.pattern;      import com.eehome.app.mail.imailconstant;   import  com.eehome.app.mail.model.routerpassauth;     /**   *  @author  wensong    * 2010-9-4  pm 03:34:58   */   public class routeiputils  {          private final static RouteIpUtils  Routeiputils = new routeiputils ();                      private routeiputils ()  {          }          public static routeiputils  getinstance ()  {           //instance of the validator tool for registration          &NBsp;  authenticator.setdefault (New routerpassauth ());            return routeIpUtils;       }           public string getrouteip ()  throws IOException {            stringbuffer wanpacket = getwanpacket ();           return getfirstip (wanpacket);        }          /**       *  Get the data on the status page in the routing Web        *        *  @return        *  @throws  IOException       */        private stringbuffer getwanpacket ()  throws ioexception  {           url url = new url ( imailconstant.route_web_state);           InputStream  ins = null;           try {                ins = url.openconnection (). getInputStream ();                Bufferedreader reader = new bufferedreader (New inputstreamreader (INS));               String str;                boolean flag = false;                stringbuffer wanpacket  = new stringbuffer ();               int num = 3;                while  (str =  Reader.readline ())  != null && num > 0  {                    if  (Str.contains ("var  wanpara = new array ("))  {                        flag = true;                    }                    if  (flag)  {                     &nbsP;  wanpacket.append (str);                        num--;                    }                }                return wanPacket;           }finally{                if (ins!=null) {                   ins.close ();                }            }       }          &nBsp;private string getfirstip (stringbuffer wanpacket)  {            //  find the first matching IP in the packet, that is ip            pattern p = pattern.compile ("\\d+\\.\\d+\\.\\d+\\.\\d+");            matcher m = p.matcher (wanpacket); &nb

Related Article

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.