public static void RestartRouter(string routerIP, string name, string pwd)
{
WebClient client = new WebClient();
string str = Convert.ToBase64String(Encoding.Default.GetBytes(string.Format("{0}:{1}", name, pwd)));
client.Headers["Authorization"] = "Basic " + str;
client.DownloadString("http://" + routerIP + "/userRpm/SysRebootRpm.htm?Reboot=%D6%D8%C6%F4%C2%B7%D3%C9%C6%F7");
client.Dispose();
}
private static void RestartRouter(string userName,string password)
{
CookieContainer container = new CookieContainer();
string requestUriString = "http://192.168.1.1/userRpm/SysRebootRpm.htm?Reboot=%D6%D8%C6%F4%C2%B7%D3%C9%C6%F7";
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(requestUriString);
request.Method = "GET";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;CIBA)";
request.CookieContainer = container;
request.KeepAlive = true;
request.Accept = "*/*";
request.Timeout = 0xbb8;
request.PreAuthenticate = true;
CredentialCache cache = new CredentialCache();
cache.Add(new Uri(requestUriString), "Basic", new NetworkCredential(userName, password));
request.Credentials = cache;
try
{
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
response.Cookies = container.GetCookies(request.RequestUri);
new StreamReader(response.GetResponseStream(), Encoding.Default).Close();
response.Close();
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
}
}c#重启路由方法
最新推荐文章于 2017-03-15 10:29:12 发布
本文提供了两个使用C#实现的重启路由器的方法。一种是通过WebClient发送带有认证信息的请求来重启,另一种则是通过创建HttpWebRequest对象并设置必要的HTTP头信息来完成。这两种方法都涉及到了基本的身份验证过程。
220

被折叠的 条评论
为什么被折叠?



