C # uses Dotras to operate ADSL

Source: Internet
Author: User

Open Source project Address: http://dotras.codeplex.com/

Using this can be convenient to operate ADSL dial, disconnect. There are detailed development documentation that you need to see for yourself.

        /// <summary>        ///Create or update a PPPoE connection (specify PPPoE name)/// </summary>        voidCreateorupdatepppoe (stringupdatepppoename) {Rasdialer Dialer=NewRasdialer (); Rasphonebook Allusersphonebook=NewRasphonebook (); stringPath =Rasphonebook.getphonebookpath (rasphonebooktype.allusers);            Allusersphonebook.open (path); //If PPPoE already exists for that name, update the PPPoE server address            if(AllUsersPhoneBook.Entries.Contains (updatepppoename)) {ALLUSERSPHONEBOOK.ENTRIES[UPDATEPPP Oename]. PhoneNumber=" "; //the update of the server address is always successful regardless of whether the current PPPoE is connected, and if it is connected, it will require a PPPoE reboot to functionAllusersphonebook.entries[updatepppoename].            Update (); }            //Create a new PPPoE            Else            {                stringAdds =string.                Empty; ReadOnlyCollection<RasDevice> ReadOnlyCollection =rasdevice.getdevices (); //foreach (var col in ReadOnlyCollection)//                {                //adds + = Col. Name + ":" + Col.                Devicetype.tostring () + "| | |"; //                }                //_log.                Info ("Devices is:" + adds); //Find the device that'll be a used to dial the connection.Rasdevice device = Rasdevice.getdevices (). Where (o = O.devicetype = =Rasdevicetype.pppoe).                First (); Rasentry entry= Rasentry.createbroadbandentry (updatepppoename, device);//Establish broadband connection entryEntry. PhoneNumber =" ";            ALLUSERSPHONEBOOK.ENTRIES.ADD (entry); }        }        /// <summary>        ///disconnecting from a broadband connection/// </summary>         Public voidDisconnect () {ReadOnlyCollection<RasConnection> conlist =rasconnection.getactiveconnections (); foreach(Rasconnection coninchconlist) {con.            Hangup (); }        }        /// <summary>        ///Broadband Connection, Success returns TRUE, Failure returns false/// </summary>        /// <param name= "Pppoename" >Broadband Connection Name</param>        /// <param name= "username" >Broadband Account</param>        /// <param name= "password" >Broadband Password</param>        /// <returns></returns>         Public BOOLConnect (stringPppoename,stringUsernamestringPasswordref stringmsg) {            Try{Createorupdatepppoe (pppoename); using(Rasdialer dialer =NewRasdialer ()) {Dialer. EntryName=Pppoename; Dialer. Allowusestoredcredentials=true; Dialer. Timeout= +; Dialer. Phonebookpath=Rasphonebook.getphonebookpath (rasphonebooktype.allusers); Dialer. Credentials=Newnetworkcredential (username, password); Dialer.                    Dial (); return true; }            }            Catch(Rasexception re) {msg= Re. ErrorCode +" "+Re.                Message; return false; }        }    }

C # uses Dotras to operate ADSL

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.