Update Tp-link router's extranet IP to peanut shell dynamic IP parsing

Source: Internet
Author: User

Originally always use the Tp-link router itself with the peanut shell Dynamic DNS plus Router port mapping function, can be directly accessed from the external network to the intranet computer port.

Later found that the peanut shells provided by the resolution IP can not access the intranet computer, after a check, found that the router's external network IP and access to the external Web page when the IP address of the display is inconsistent,

When using the IP test to access the Web page, the intranet can not be accessed, and the external IP of the monitor on the router is accessible to the intranet.

Should be the ISP provider (I use Unicom broadband) to use the NAT conversion.

Another investigation, peanut shells and other dynamic DNS service providers offer a possible solution, depending on how the lines are handled in different internal

I estimate that it is possible to solve the IP address problem caused by NAT conversion, but, most importantly, this service is a charge service, can only find another way.

The peanut shell was later found to provide manual update of the dynamic IP function, that is, the use of HTTP GET method to manually update the IP address,

The investigation also found that it should be possible to get the extranet IP from the Management Web page of the router, so after investigation and testing, it can be realized, and the automatic update of the software can realize the auto-updating IP function of the peanut shell client.

The main code "C #" that will be used is logged as follows:

        <summary>///Get the Tp-link router's extranet IP address///This function assumes that the router is in a connected state and no longer determines whether or not to connect to the network status//</summar y>//<param name= "STRTPIP" >tp-link router IP address </param>///<param name= "strUserName" >tp-l Administrative user password for the ink router </param>///<param name= "strpassword" >tp-link router </param>//<retur ns> extranet IP address, null representation get failed </returns> private string Getwanip (String Strtpip, String strUserName, String strpasswor d) {//web page URL containing tp-link router status information string strtpurl = "/http" + Strtpip + "/userrpm/statusrpm.ht            M "; Set parameters for getting status information web page content System.Net.HttpWebRequest objrequest = (System.Net.HttpWebRequest) System.Net.HttpWebReques            T.create (Strtpurl);            Objrequest.referer = Strtpurl;                        Objrequest.credentials = new System.Net.NetworkCredential (strUserName, strpassword);            Get Results Information content setlogmessage (0, "Try to get router status information content"); SysTem.Net.HttpWebResponse objresponse = (System.Net.HttpWebResponse) objrequest.getresponse ();            Setlogmessage (1, "Router status information acquired"); Get the result content text System.IO.StreamReader Objresponsereader = new System.IO.StreamReader (objresponse.getresponsestream            (), Encoding.default);            String strresponsetext = Objresponsereader.readtoend ();            Objresponsereader.close ();            Objresponse.close ();            Find the data array location containing the extranet IP address setlogmessage (1, "Find the data array location containing the extranet IP address");            int intpos = Strresponsetext.indexof ("var Wanpara = new Array");                if (Intpos < 0) {setlogmessage (0, "* * * * Find data Array location with extranet IP address failed");            Return "";            }//Find the external IP address location setlogmessage (1, "Find out the IP address location of the network");            int intPos2 = Strresponsetext.indexof ("\", \n\ "", intpos);                if (IntPos2 < 0) {setlogmessage (0, "* * * * * * Find the location of the extranet IP address failed");            Return ""; }            Find the end location of the extranet IP address setlogmessage (1, "Find the end location of the extranet IP address");            int intPos3 = Strresponsetext.indexof ("\" ", IntPos2 + 4);                if (IntPos3 < 0) {setlogmessage (0, "* * * * Find the end of the extranet IP address failed");            Return "";            }//Get extranet IP address int intippos = IntPos2 + 4;            String strwanip = Strresponsetext.substring (Intippos, Intpos3-intippos);            Setlogmessage (0, "Get Results out of network IP address: [" + Strwanip + "]");        return strwanip; }///<summary>//Update dynamic IP address to peanut shell///</summary>//<param name= "Strorayusernam E "> Peanut shell User name </param>//<param name=" Stroraypassword "> Peanut Shell Password </param>///<param name=" s Trhostname "> Peanut shell Domain name (with multiple domain names separated by commas) </param>//<param name=" Strwanip "> the IP to be updated, or empty, the IP address obtained by the peanut shell when empty is the quasi-</ Param>//<returns> Success </returns> private bool Updateorayddnsip (string StrorayuseRname, String Stroraypassword, String strhostname, String strwanip) {//update DDNS URL string st            Rupdateurl = "Http://ddns.oray.com/ph/update?hostname=" + strhostname + "&myip=" + strwanip; Create an HTTP request object System.Net.HttpWebRequest objrequest = (System.Net.HttpWebRequest) System.Net.HttpWebRequest.Creat            E (Strupdateurl);            Set the relevant parameters objrequest.useragent = "Oray";                        Objrequest.method = "GET"; Gets the user name password of the BASE64 encoded string strbase64code = Convert.tobase64string (string.            Format ("{0}:{1}", Strorayusername, Stroraypassword));            Add Authorization to HTTP header objRequest.Headers.Add ("Authorization", "Basic" + Strbase64code);            Try to update and get the result information setlogmessage (0, "Attempt to update dynamic IP to Peanut shell");            System.Net.HttpWebResponse objresponse = (System.Net.HttpWebResponse) objrequest.getresponse (); Get the result information text setlogmessage (1, "Update dynamicState IP to the peanut Shell complete "); System.IO.StreamReader Objresponsereader = new System.IO.StreamReader (Objresponse.getresponsestream (),            Encoding.default);            String strresponsetext = Objresponsereader.readtoend ();            Objresponsereader.close ();            Objresponse.close ();            Setlogmessage (0, "Update results information: [" + Strresponsetext + "]");            Check if the result is successful if (Strresponsetext.indexof ("good") >= 0 | | strresponsetext.indexof ("NOCHG") >= 0)                {setlogmessage (1, "Update dynamic IP address succeeded");            return true;                } else {setlogmessage (0, "* * * Update dynamic IP address failed");            return false; }        }

The above code only applies to the Tp-link router, tested on the Tp-link router tl-wr845n model, because no other model is tested, so no other model of the router can be guaranteed to work properly.

If Tp-link other model routers are not available, you can see if the Status Monitor Web page URL matches the URL in the code above, and use the HTTP Capture tool to view the header content and response content of the page.

It should be possible to adjust the URL, the header content for the get, and the location lookup string method where the extranet IP is located in the content of response.

Similarly, for other manufacturers of routers, I feel that the same can be achieved, view the Router status information page source code and use the HTTP Capture tool to view relevant information, you should be able to achieve similar functions.

Update Tp-link router's extranet IP to peanut shell dynamic IP parsing

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.