使用c#实现简单的路由器重启功能
2012-04-17 17:57
681 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace routerApp
{
class Program
{
static void Main(string[] args)
{
RestartRouter();
}
private static void RestartRouter()
{
HttpWebRequest request = null;
HttpWebResponse response = null;
string gethost = string.Empty;
CookieContainer cc = new CookieContainer();
string Cookiesstr = string.Empty;
try
{
gethost = "http://192.168.1.1/userRpm/SysRebootRpm.htm?Reboot=%D6%D8%C6%F4%C2%B7%D3%C9%C6%F7"; //路由器重启的地址
request = (HttpWebRequest)WebRequest.Create(gethost);
request.Method = "GET";
request.KeepAlive = true;
request.Headers.Add("Authorization:" + "Basic YWRtaW46YWRtaW4=");//授权的请求
request.CookieContainer = cc;
request.AllowAutoRedirect = false;
response = (HttpWebResponse)request.GetResponse();
//设置cookie
Cookiesstr = request.CookieContainer.GetCookieHeader(request.RequestUri);
//取再次跳转链接
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
string content = sr.ReadToEnd();
request.Abort();
sr.Close();
response.Close();
}
catch (Exception e)
{
Console.WriteLine("路由器重启失败!");
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace routerApp
{
class Program
{
static void Main(string[] args)
{
RestartRouter();
}
private static void RestartRouter()
{
HttpWebRequest request = null;
HttpWebResponse response = null;
string gethost = string.Empty;
CookieContainer cc = new CookieContainer();
string Cookiesstr = string.Empty;
try
{
gethost = "http://192.168.1.1/userRpm/SysRebootRpm.htm?Reboot=%D6%D8%C6%F4%C2%B7%D3%C9%C6%F7"; //路由器重启的地址
request = (HttpWebRequest)WebRequest.Create(gethost);
request.Method = "GET";
request.KeepAlive = true;
request.Headers.Add("Authorization:" + "Basic YWRtaW46YWRtaW4=");//授权的请求
request.CookieContainer = cc;
request.AllowAutoRedirect = false;
response = (HttpWebResponse)request.GetResponse();
//设置cookie
Cookiesstr = request.CookieContainer.GetCookieHeader(request.RequestUri);
//取再次跳转链接
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
string content = sr.ReadToEnd();
request.Abort();
sr.Close();
response.Close();
}
catch (Exception e)
{
Console.WriteLine("路由器重启失败!");
}
}
}
}
相关文章推荐
- C#使用命令行方式实现Ping简单功能
- C#使用命令行方式实现Ping简单功能 http://www.cnblogs.com/kevinton/archive/2007/06/28/798581.html
- C#实现简单的3DES加密解密功能示例
- 使用sinatra实现简单的crud功能
- 使用简单的html+css+javacsript实现dialog功能
- yii2.0使用插件实现一个简单的上传功能
- [C#] .NET4.0中使用4.5中的 async/await 功能实现异
- 如何使用C#自带的GDI+双缓冲类BufferedGraphics实现双缓冲功能
- 使用bitmapData简单实现涂鸦中的橡皮功能[Flex]
- 使用UIScrollView和UIPageControl实现一个简单的图片浏览功能
- java Socket 的简单使用 实现对话交流功能
- Servlet自学第13讲:使用纯Servlet实现简单登录功能
- ASP.NET使用AspNetPager实现简单的分页功能
- C# 实现注销、关机、重启电脑功能
- 用C#实现实现简单的 Ping 的功能,用于测试网络是否已经联通
- wheel自定义控件,实现城市三级联动,时间选择的功能简单使用
- 使用vue + less 实现简单换肤功能的示例
- unity实现简单的加密使用次数限制时间限制功能
- C#实现SMTP服务器,使用TCP命令实现,功能比较完善
- 使用Python实现简单的服务器功能