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

Zada ·
更新时间:2024-11-11
· 783 次阅读

代码如下:
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-www-form-urlencoded";
        oRequest.UserAgent = "Mozilla/4.0 (compatible; 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("断开登录失败");
        }
    }
}

您可能感兴趣的文章:用C#写的ADSL拨号程序的代码示例c#判断网络连接状态的示例分享c#判断网络连接状态C#中判断本地系统的网络连接状态的方法c# 连接字符串数据库服务器端口号 .net状态服务器端口号C#.NET获取拨号连接的宽带连接方法



C# 路由器 ip 连接 公网ip 路由

需要 登录 后方可回复, 如果你还没有账号请 注册新账号