博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用c#实现简单的路由器重启功能
阅读量:2287 次
发布时间:2019-05-09

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

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("路由器重启失败!");  
            }
        }
    }
}

转载地址:http://oyunb.baihongyu.com/

你可能感兴趣的文章
LeetCode 59. Spiral Matrix II 解题报告
查看>>
Windows环境下编译Assimp库生成Android可用的.so文件
查看>>
华为OD两轮技术面试
查看>>
JAVA中的异常
查看>>
关于Git的一点思考
查看>>
单元测试
查看>>
2020-08-26
查看>>
RFC 959 (rfc959) - File Transfer Protocol
查看>>
【代码】Visual C++线程同步技术剖析:临界区,事件,信号量,互斥量
查看>>
Windows邮件槽(Mailslot)
查看>>
ubuntu固定IP地址
查看>>
查看你使用最多的10条shell命令
查看>>
scanf和cin的返回值
查看>>
[转]C/C++ 数据对齐知识摘要
查看>>
[转]sed 学习笔记
查看>>
[转]文件压缩tar
查看>>
Linux信号
查看>>
nanosleep is better than sleep and usleep
查看>>
清空输出缓冲区
查看>>
Ubuntu常用安装
查看>>