C#实现路由器断开连接,更改公网ip的实例代码

时间:2021-05-20

复制代码 代码如下:
public static void Disconnect(){
string url = "断 线";
string uri = "http://192.168.1.1/userRpm/StatusRpm.htm?Disconnect=" + System.Web.HttpUtility.UrlEncode(url, System.Text.Encoding.GetEncoding("gb2312")) + "&wan=1";
string sUser = "admin";
string sPwd = "admin";
string sDomain = "";
NetworkCredential oCredential;
HttpWebRequest oRequest = (System.Net.HttpWebRequest)WebRequest.Create(uri);
if (oRequest != null)
{
oRequest.ProtocolVersion = HttpVersion.Version11;// send request
oRequest.Method = "GET";
oRequest.ContentType = "application/x-patible; MSIE 7.0; Windows NT 5.1; GTB6.4; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
oRequest.Referer = "http://192.168.1.1";

if (sUser != String.Empty)
{
oCredential = new NetworkCredential(sUser, sPwd, sDomain);
oRequest.Credentials = oCredential.GetCredential(new Uri(uri), String.Empty);
}
else
{
oRequest.Credentials = CredentialCache.DefaultCredentials;
}
StreamReader sr = new StreamReader(oRequest.GetResponse().GetResponseStream(), System.Text.Encoding.Default);
string line = sr.ReadToEnd();
sr.Close();
if (line.IndexOf("LAN口状态") > -1)//登录成功
{
Console.WriteLine("断开登录成功");
}
else
{
Console.WriteLine("断开登录失败");
}
}
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章