博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c#重起 普通路由器
阅读量:4955 次
发布时间:2019-06-12

本文共 3230 字,大约阅读时间需要 10 分钟。

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

转载于:https://www.cnblogs.com/bigdata007/p/4955869.html

你可能感兴趣的文章
JIRA问题状态已关闭,但是解决结果还是未解决
查看>>
LayoutInflater
查看>>
前端小技巧
查看>>
未将对象引用设置到对象的实例
查看>>
MATLAB GUI制作快速入门
查看>>
自制数据挖掘工具分析北京房价 (二) 数据清洗
查看>>
Noip2016day2 组合数问题problem
查看>>
2014-10-4 NOIP模拟赛
查看>>
【NOIP模拟赛】收银员(一道差分约束好题)
查看>>
poj 1635 Subway tree systems(树的最小表示)
查看>>
Spring.FactoryBean & BeanFactory Diff
查看>>
Effective C++ -----条款10: 令operator=返回一个reference to *this
查看>>
ADROID 2.2 语言定制
查看>>
SQL 查询 总结 【行子查询 ; 列子查询 ; 表子查询 ; 自链接 ; 内连接 ;外连接 ; 无规则链接 ……】...
查看>>
DML-修改
查看>>
【CSS3 探索发现】系列二:打造一组闪亮的半透明按钮效果
查看>>
codeblocks-17.12mingw-nosetup(mingw编译,绿色免安装版)的下载、安装及设置一
查看>>
10进制整数转62进制的函数
查看>>
[置顶] iptables 性能 测试
查看>>
myeclipse 导入 import maven web project
查看>>