如何以编程方式重新启动Netgear调制解调器?

时间:2014-03-18 07:14:17

标签: c# httprequest restart modem

我想从C#windows应用程序对NETGEAR DGN2200进行热重置,我的调制解调器是标准的Netgear调制解调器/路由器。没有telnet可以吗?

1 个答案:

答案 0 :(得分:4)

我希望这段代码能解决你的问题,这就是我从C#重启路由器的方法 您可以在192.168.0.1模仿用户对Netgear调制解调器Web界面的http请求。您可以使用Fiddler获取确切的Web请求,只需编辑正确的标头即可。 请注意request.Headers [“Authorization”]它应与您的调制解调器的用户名和密码相关联,它通常是“Admin”“Admin”with netgear,但它可能是由您的Internet服务提供商预先配置的。

 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();
           }
       }