C # implement vro disconnection and change the public ip instance code

Source: Internet
Author: User

Copy codeThe Code is as follows: public static void Disconnect (){
String url = "disconnected ";
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.20.6.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 port status")>-1) // logon successful
{
Console. WriteLine ("Logon disconnected ");
}
Else
{
Console. WriteLine ("failed to log on disconnected ");
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.