用于重启 TP link 路由器的 C# 脚本
C# script for rebooting TP link router
大家好我是编程新手,我需要创建一个 C# 脚本来重启我的 TP link 路由器这样做我使用了这个代码:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://192.168.0.1/reboot.cgi");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Referer = @"http://192.168.0.1/DIAG_diag.htm";
request.UserAgent = @"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36";
request.Accept = @"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
request.Credentials = new NetworkCredential("Admin", "Admin");
var requestBody = Encoding.UTF8.GetBytes("Reboot = Reboot");
request.Host = "192.168.0.1";
request.Headers["Authorization"] = "Basic QWRtaW46QWRtaW4=";
request.Headers["Origin"] = @"http://192.168.0.1";
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(requestBody, 0, requestBody.Length);
}
string output = string.Empty;
using (var response = request.GetResponse())
{
using (var stream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1252)))
{
output = stream.ReadToEnd();
}
}
但它没有完成任务。感谢您的帮助和关注。
太绕口了
在您的路由器上启用 SSH 或 Telnet。分别通过端口22或端口23发送重启命令。
这是做同样事情的 VBS。
Option explicit
Dim oShell
set oShell= Wscript.CreateObject("WScript.Shell")
oShell.Run "telnet"
WScript.Sleep 500
oShell.Sendkeys "open 192.168.1.1~"
WScript.Sleep 500
oShell.Sendkeys "admin~"
WScript.Sleep 500
oShell.Sendkeys "password123~"
WScript.Sleep 500
oShell.Sendkeys "reboot~"
WScript.Sleep 3000
oShell.Sendkeys "{ENTER}"
WScript.Sleep 500
oShell.Sendkeys "quit~"
Wscript.Quit
大家好我是编程新手,我需要创建一个 C# 脚本来重启我的 TP link 路由器这样做我使用了这个代码:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://192.168.0.1/reboot.cgi");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Referer = @"http://192.168.0.1/DIAG_diag.htm";
request.UserAgent = @"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36";
request.Accept = @"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
request.Credentials = new NetworkCredential("Admin", "Admin");
var requestBody = Encoding.UTF8.GetBytes("Reboot = Reboot");
request.Host = "192.168.0.1";
request.Headers["Authorization"] = "Basic QWRtaW46QWRtaW4=";
request.Headers["Origin"] = @"http://192.168.0.1";
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(requestBody, 0, requestBody.Length);
}
string output = string.Empty;
using (var response = request.GetResponse())
{
using (var stream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1252)))
{
output = stream.ReadToEnd();
}
}
但它没有完成任务。感谢您的帮助和关注。
太绕口了
在您的路由器上启用 SSH 或 Telnet。分别通过端口22或端口23发送重启命令。
这是做同样事情的 VBS。
Option explicit
Dim oShell
set oShell= Wscript.CreateObject("WScript.Shell")
oShell.Run "telnet"
WScript.Sleep 500
oShell.Sendkeys "open 192.168.1.1~"
WScript.Sleep 500
oShell.Sendkeys "admin~"
WScript.Sleep 500
oShell.Sendkeys "password123~"
WScript.Sleep 500
oShell.Sendkeys "reboot~"
WScript.Sleep 3000
oShell.Sendkeys "{ENTER}"
WScript.Sleep 500
oShell.Sendkeys "quit~"
Wscript.Quit