Namespace microshaoft {using system; using RAS; public class class1 {static void main (string [] ARGs) {console. writeline ("Hello World"); console. writeline (environment. version. tostring (); console. writeline ("PLS input entryname (network connection name):"); string entryname = console. readline (); console. writeline ("PLS input username (username):"); string username = console. readline (); console. writeline ("PLS input passwo Rd (password): "); string Password = consolereadmaskline ('*', true); rasmanager Rm = new rasmanager (); RM. entryname = entryname; // entry name in phonebook RM. username = username; RM. password = password; int r =-1; r = RM. connect (); string S = "failed"; if (r = 0) {S = "successful";} console. writeline ("\ n Network Connection: \" {0} \ "dial-up Internet {1}, result: {2}", entryname, S, R); console. readline ();} public static string consolereadma Skline (char passwordchar, bool withmask) {string Password = ""; consolekey CK; string S = @"~! @ # $ % & * () _ + '1970-= "; // enter the character S + = @" qwertyuiop {}| qwertyuiop [] \ "; S + = "asdfghjkl: \" asdfghjkl; '"; S + =" zxcvbnm <>? Zxcvbnm ,. /"; do {consolekeyinfo cki = console. readkey (true); char c = cki. keychar; ck = cki. key; int P = console. cursorleft; If (Ck = consolekey. backspace) {string left = ""; if (P> 0) {left = password. substring (0, P-1);} string right = password. substring (p); Password = left + right; console. write (c); string output = right; if (withmask) {output = getpasswordchars (right, passwordchar );} Output + = "\ 0"; console. write (output); If (P> 0) {p -- ;}} else if (Ck = consolekey. delete) {string left = ""; if (P> 0) {left = password. substring (0, P);} string right = ""; if (P <password. length) {right = password. substring (p + 1);} Password = left + right; // console. write (right + ""); string output = right; if (withmask) {output = getpasswordchars (right, passwordchar);} output + = "\ 0"; console. write (output);} else {If (S. indexof (c)> = 0) {string left = password. substring (0, P); string right = password. substring (p); Password = left + C + right; string output = C + right; if (withmask) {output = getpasswordchars (C + right, passwordchar);} console. write (output); P ++;} else {Switch (CK) {Case consolekey. leftarrow: If (P> 0) {p --;} break; Case consolekey. rightarr Ow: If (P <password. length) {P ++;} break; Case consolekey. home: P = 0; break; Case consolekey. end: P = password. length; break; default: console. beep (); break ;}} console. cursorleft = P;} while (CK! = Consolekey. enter); Return password;} Private Static string getpasswordchars (string S, char c) {string passwordchars = ""; for (INT I = 0; I <S. length; I ++) {passwordchars + = C;} return passwordchars ;}}} namespace Ras {using system; using system. runtime. interopservices; public class rasmanager {public const int ras_maxentryname = 256; Public const int ras_maxphonenumber = 128; Public const int unlen = 256; Public const int pwlen = 256; public const int dnlen = 15; Public const int max_path = 260; Public const int ras_maxdevicetype = 16; Public const int ras_maxcallbacknumber = ras_maxphonenumber; Public Delegate void callback (uint unmsg, int rasconnstate, int dwerror); [structlayout (layoutkind. sequential, pack = 4, charset = charset. auto)] public struct rasdialparams {public int dwsize; [financialas (unmanagedtype. byvaltstr, sizeconst = ras_maxentryname + 1)] Public String szentryname; [financialas (unmanagedtype. byvaltstr, sizeconst = ras_maxphonenumber + 1)] Public String szphonenumber; [financialas (unmanagedtype. byvaltstr, sizeconst = ras_maxcallbacknumber + 1)] Public String szcallbacknumber; [financialas (unmanagedtype. byvaltstr, sizeconst = unlen + 1)] Public String szusername; [financialas (unmanagedtype. byvaltstr, sizeconst = pwlen + 1)] Public String szpassword; [financialas (unmanagedtype. byvaltstr, sizeconst = dnlen + 1)] Public String szdomain; Public int dwsubentry; Public int dwcallbackid;} [dllimport ("rasapi32.dll", charset = charset. auto)] public static extern int rasdial (INT second, string lpszphonebook, ref rasdialparams second, int dwnotifiertype, callback second, ref int lphrasconn); Private rasdialparams; private int connection; public rasmanager () {connection = 0; rasdialparams = new rasdialparams (); rasdialparams. dwsize = marshal. sizeof (rasdialparams);} # region properties Public String username {get {return rasdialparams. szusername;} set {rasdialparams. szusername = value ;}} Public String password {get {return rasdialparams. szpassword;} set {rasdialparams. szpassword = value ;}} Public String entryname {get {return rasdialparams. szentryname;} set {rasdialparams. szentryname = value ;}# endregion public int connect () {callback rasdialfunc = new callback (rasmanager. rasdialfunc); rasdialparams. szentryname + = "\ 0"; rasdialparams. szusername + = "\ 0"; rasdialparams. szpassword + = "\ 0"; int result = rasdial (0, null, ref rasdialparams, 0, rasdialfunc, ref connection); return result;} public static void rasdialfunc (uint unmsg, int rasconnstate, int dwerror) {console. writeline ("Callback: unmsg = {0}, rasconnstate = {1}, dwerror = {2}", unmsg, rasconnstate, dwerror );}}}