سؤال

I would like to do a warm reset to my NETGEAR DGN2200 from a C# windows application, my modem is a standard Netgear modem/router. Is it possible without telnet?

هل كانت مفيدة؟

المحلول

I hope this code will solve your question, this is how I restart my router from C# You can imitate a user's http request to the Netgear modem web interface at 192.168.0.1. you can use Fiddler to get the exact web request, just edit the right headers to the request. Pay attention to request.Headers["Authorization"] it should correlate with your Modem's username and password, it's usually "Admin" "Admin" with netgear but it might be preconfigured by your Internet service provider.

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://192.168.0.1/reboot.cgi");
          request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Referer = @"http://192.168.0.1/DIAG_diag.htm";
        request.UserAgent = @"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36";
        request.Accept = @"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
        request.Credentials = new NetworkCredential("Admin", "Admin");
        var requestBody = Encoding.UTF8.GetBytes("Reboot = Reboot");
        request.Host = "192.168.0.1";
        request.Headers["Authorization"] = "Basic QWRtaW46QWRtaW4=";
        request.Headers["Origin"] = @"http://192.168.0.1";
       using (var requestStream = request.GetRequestStream())
       {
           requestStream.Write(requestBody, 0, requestBody.Length);
       }

       string output = string.Empty;
       using (var response = request.GetResponse())
       {
           using (var stream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1252)))
           {
               output = stream.ReadToEnd();
           }
       }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top