码迷,mamicode.com
首页 > Windows程序 > 详细

c#重起 普通路由器

时间:2015-11-11 14:42:23      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:

using DotNet.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace reboot2
{
class Program
{
static void Main(string[] args)
{

Disconnect();
Thread.Sleep(100);
connect();
while (true)
{
try
{
if (IsConnectedPing())
//if(IsConnectedToInternet())
{
Console.WriteLine("\nConnectedToInternet ...\n");
break;
}
}
catch
{
Console.WriteLine("\n\nerror ...\n");
}
Thread.Sleep(1000);
}
ip();
// Console.ReadLine();
}

private static void ip()
{

//
var _UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0";
HttpHelper http = new HttpHelper();
var _Referer = "http://www.ip138.com";
HttpItem item = new HttpItem()
{

Encoding = Encoding.Default,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
URL = "http://1111.ip138.com/ic.asp",//URL这里都是测试 必需项
Method = "get",//URL 可选项 默认为Get
UserAgent = _UserAgent,
Referer = _Referer

};
//得到HTML代码
HttpResult result = http.GetHtml(item);
Console.WriteLine(result.Html);
}
private static void Disconnect()
{
var url = "http://192.168.1.1/userRpm/StatusRpm.htm?Disconnect=%B6%CF%20%CF%DF&wan=1";
var cookie = "Authorization=Basic%20YWRtaW46cWluaGFuMjAxNA%3D%3D; ChgPwdSubTag=";
var _UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0";
var _Referer = "http://192.168.1.1/userRpm/StatusRpm.htm";
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
Cookie = cookie,
Encoding = Encoding.Default,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
URL = url,//URL这里都是测试 必需项
Method = "get",//URL 可选项 默认为Get
UserAgent = _UserAgent,
Referer = _Referer

};
//得到HTML代码
HttpResult result = http.GetHtml(item);
Console.WriteLine("Disconnect....");
// Console.ReadLine();

}
private static void connect()
{
var url = "http://192.168.1.1/userRpm/StatusRpm.htm?Connect=%C1%AC%20%BD%D3&wan=1";
var cookie = "Authorization=Basic%20YWRtaW46cWluaGFuMjAxNA%3D%3D; ChgPwdSubTag=";
var _UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0";
var _Referer = "http://192.168.1.1/userRpm/StatusRpm.htm?Disconnect=%B6%CF%20%CF%DF&wan=1";
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
Cookie = cookie,
Encoding = Encoding.Default,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
URL = url,//URL这里都是测试 必需项
Method = "get",//URL 可选项 默认为Get
UserAgent = _UserAgent,
Referer = _Referer
};
//得到HTML代码
HttpResult result = http.GetHtml(item);
Console.WriteLine("connect....");
// Console.WriteLine(result.Html);
// Console.ReadLine();

}
public static bool IsConnectedPing()
{
Console.WriteLine("weixin.sogou.com");
string hostNameOrAddress = "weixin.sogou.com";
Ping ping = new Ping();
PingReply pingReply = ping.Send(hostNameOrAddress);
if (pingReply.Status == IPStatus.Success)
{
Console.WriteLine("网络连接成功, 执行下面任务...");
ping.Dispose();
return true;
}
int i = 0;
while (i < 12)
{
Thread.Sleep(50);
pingReply = ping.Send(hostNameOrAddress);
Console.WriteLine(pingReply.Status);
i++;
if (pingReply.Status == IPStatus.Success)
{
ping.Dispose();
return true;
}
}
Console.WriteLine("重新尝试连接超过12次,连接失败程序结束");
ping.Dispose();
return false;
}
}
}

c#重起 普通路由器

标签:

原文地址:http://www.cnblogs.com/bigdata007/p/4955869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!