/// <summary> /// 创建或更新一个PPPOE连接(指定PPPOE名称) /// </summary> public void CreateOrUpdatePPPOE(string updatePPPOEname) { RasDialer dialer = new RasDialer(); RasPhoneBook allUsersPhoneBook = new RasPhoneBook(); string path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); allUsersPhoneBook.Open(path); // 如果已经该名称的PPPOE已经存在,则更新这个PPPOE服务器地址 if (allUsersPhoneBook.Entries.Contains(updatePPPOEname)) { allUsersPhoneBook.Entries[updatePPPOEname].PhoneNumber = " "; // 不管当前PPPOE是否连接,服务器地址的更新总能成功,如果正在连接,则需要PPPOE重启后才能起作用 allUsersPhoneBook.Entries[updatePPPOEname].Update(); } // 创建一个新PPPOE else { string adds = string.Empty; ReadOnlyCollection <RasDevice> readOnlyCollection = RasDevice.GetDevices(); // foreach (var col in readOnlyCollection) // { // adds += col.Name + ":" + col.DeviceType.ToString() + "|||"; // } // _log.Info("Devices are : " + adds); // Find the device that will be used to dial the connection. RasDevice device = RasDevice.GetDevices().Where(o => o.DeviceType == RasDeviceType.PPPoE).First(); RasEntry entry = RasEntry.CreateBroadbandEntry(updatePPPOEname, device); //建立宽带连接Entry entry.PhoneNumber = " "; allUsersPhoneBook.Entries.Add(entry); } }
public void CreateConnect(string ConnectName) { RasDialer dialer = new RasDialer(); RasPhoneBook book = new RasPhoneBook(); try { book.Open(RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User)); if (book.Entries.Contains(ConnectName)) { book.Entries[ConnectName].PhoneNumber = " "; book.Entries[ConnectName].Update(); } else { System.Collections.ObjectModel.ReadOnlyCollection <RasDevice> readOnlyCollection = RasDevice.GetDevices(); RasDevice device = RasDevice.GetDevices().Where(o => o.DeviceType == RasDeviceType.PPPoE).First(); RasEntry entry = RasEntry.CreateBroadbandEntry(ConnectName, device); entry.PhoneNumber = " "; book.Entries.Add(entry); } } catch (Exception) { lb_status.Content = "创建PPPoE连接失败"; } }
/// <summary> /// 创建一个PPPOE连接 /// </summary> /// <param name="updatePPPOEName"></param> private void CreatePPPOE(string updatePPPOEName) { var conns = RasConnection.GetActiveConnections(); if (conns != null) { foreach (var conn in conns) { conn.HangUp(); } } var allUsersPhoneBook = new RasPhoneBook(); var path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); allUsersPhoneBook.Open(path); //创建一个新的PPPOE var address = string.Empty; var readOnlyCollection = RasDevice.GetDevices(); var device = RasDevice.GetDevices().First(o => o.DeviceType == RasDeviceType.PPPoE); //建立宽带连接 var entry = RasEntry.CreateBroadbandEntry(updatePPPOEName, device); entry.PhoneNumber = " "; if (!allUsersPhoneBook.Entries.Contains(updatePPPOEName)) { allUsersPhoneBook.Entries.Add(entry); } }
/// <summary> /// 创建或更新一个PPPOE连接(指定PPPOE名称) /// </summary> static void CreateOrUpdatePPPOE(string updatePPPOEname) { RasDialer dialer = new RasDialer(); RasPhoneBook allUsersPhoneBook = new RasPhoneBook(); string path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); allUsersPhoneBook.Open(path); // 如果已经该名称的PPPOE已经存在,则更新这个PPPOE服务器地址 if (allUsersPhoneBook.Entries.Contains(updatePPPOEname)) { allUsersPhoneBook.Entries[updatePPPOEname].PhoneNumber = " "; // 不管当前PPPOE是否连接,服务器地址的更新总能成功,如果正在连接,则需要PPPOE重启后才能起作用 allUsersPhoneBook.Entries[updatePPPOEname].Update(); } // 创建一个新PPPOE else { string adds = string.Empty; ReadOnlyCollection <RasDevice> readOnlyCollection = RasDevice.GetDevices(); RasDevice device = RasDevice.GetDevices().Where(o => o.DeviceType == RasDeviceType.PPPoE).First(); RasEntry entry = RasEntry.CreateBroadbandEntry(updatePPPOEname, device); //建立宽带连接Entry entry.PhoneNumber = " "; allUsersPhoneBook.Entries.Add(entry); } }
private void Form2_Load(object sender, EventArgs e) { this.Dialer.Timeout = 20000; this.Dialer.Credentials = null; this.Dialer.EapOptions = new DotRas.RasEapOptions(false, false, false); this.Dialer.HangUpPollingInterval = 0; this.Dialer.Options = new DotRas.RasDialOptions(false, false, false, false, false, false, false, false, false, false); this.Dialer.SynchronizingObject = this; //this.Dialer.StateChanged += new System.EventHandler<DotRas.StateChangedEventArgs>(this.Dialer_StateChanged); this.Dialer.DialCompleted += new System.EventHandler <DotRas.DialCompletedEventArgs>(this.Dialer_DialCompleted); string path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); //创建VPN this.AllUsersPhoneBook.Open(path); if (!this.AllUsersPhoneBook.Entries.Contains(EntryName)) { RasEntry entry = RasEntry.CreateBroadbandEntry(EntryName, RasDevice.GetDeviceByName("(PPPoE)", RasDeviceType.PPPoE)); this.AllUsersPhoneBook.Entries.Add(entry); } InitAction(); }
/// <summary> /// 创建或更新一个PPPOE连接 /// </summary> /// <param name="updatePPPOEName"></param> private void CreateOrUpdatePPPOE(string updatePPPOEName) { var allUsersPhoneBook = new RasPhoneBook(); var path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); allUsersPhoneBook.Open(path); //如果该名称的PPPOE已经存在,则更新这个PPPOE服务器地址 if (allUsersPhoneBook.Entries.Contains(updatePPPOEName)) { allUsersPhoneBook.Entries[updatePPPOEName].PhoneNumber = " "; //不管当前PPPOE是否连接,服务器地址的更新总能成功,如果正在连接,则需要PPPOE重启后才能起作用 allUsersPhoneBook.Entries[updatePPPOEName].Update(); } //创建一个新的PPPOE else { var address = string.Empty; var readOnlyCollection = RasDevice.GetDevices(); var device = RasDevice.GetDevices().First(o => o.DeviceType == RasDeviceType.PPPoE); //建立宽带连接 var entry = RasEntry.CreateBroadbandEntry(updatePPPOEName, device); entry.PhoneNumber = " "; allUsersPhoneBook.Entries.Add(entry); } }
private Encoding defEncoding = Encoding.GetEncoding(1252); // ANSI private void CreateConnect() { RasPhoneBook book = new RasPhoneBook(); try { book.Open(RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User)); if (book.Entries.Contains(ConnectionName)) { book.Entries[ConnectionName].PhoneNumber = " "; book.Entries[ConnectionName].Update(); } else { RasDevice device = RasDevice.GetDevices(). Where(o => o.DeviceType == RasDeviceType.PPPoE).First(); RasEntry entry = RasEntry.CreateBroadbandEntry(ConnectionName, device); entry.PhoneNumber = " "; book.Entries.Add(entry); } } catch (Exception ex) { Logger.Log($"创建PPPoE连接失败({ex.Message})"); } }
/// <summary> /// 初始化PPPoE拨号器 /// </summary> /// <param name="connectName">连接名称</param> public static void Init(string connectName) { try { RasDialer dialer = new RasDialer(); RasPhoneBook phoneBook = new RasPhoneBook(); string path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User); phoneBook.Open(path); if (phoneBook.Entries.Contains(connectName)) { phoneBook.Entries[connectName].PhoneNumber = " "; phoneBook.Entries[connectName].Update(); } else { string adds = string.Empty; System.Collections.ObjectModel.ReadOnlyCollection <RasDevice> readOnlyCollection = RasDevice.GetDevices(); RasDevice device = RasDevice.GetDevices().First(o => o.DeviceType == RasDeviceType.PPPoE); RasEntry entry = RasEntry.CreateBroadbandEntry(connectName, device); entry.PhoneNumber = " "; phoneBook.Entries.Add(entry); } } catch (Exception e) { Utils.Log4Net.WriteLog(e.Message, e); } }
public void CreateConnect(string ConnectName) { RasDialer dialer = new RasDialer(); try { System.Collections.ObjectModel.ReadOnlyCollection <RasDevice> readOnlyCollection = RasDevice.GetDevices(); RasDevice device = RasDevice.GetDevices().Where(o => o.DeviceType == RasDeviceType.PPPoE).First(); RasEntry entry = RasEntry.CreateBroadbandEntry(ConnectName, device); entry.PhoneNumber = " "; } catch (Exception) { System.Windows.Forms.MessageBox.Show("创建PPPoE连接失败"); } }
/// <summary> /// Connect /// </summary> /// <param name="connectName"></param> /// <param name="userName"></param> /// <param name="password"></param> public static void Connect(string connectName, string userName, string password) { //关闭现有连接 IReadOnlyCollection <RasConnection> conns = RasConnection.GetActiveConnections(); if (conns.Count != 0) { foreach (var conn in conns) { conn.HangUp(); } } RasPhoneBook rasPhoneBook = new RasPhoneBook(); string path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); rasPhoneBook.Open(path); //创建一个新的PPPOE连接 IReadOnlyCollection <RasDevice> rasDevices = RasDevice.GetDevices(); RasDevice device = rasDevices.First(d => d.DeviceType == RasDeviceType.PPPoE); var entry = RasEntry.CreateBroadbandEntry(connectName, device); entry.PhoneNumber = userName; //如果不存在该名字的用户名和密码的连接,则Add 存在则更新 if (!rasPhoneBook.Entries.Contains(connectName)) { rasPhoneBook.Entries.Add(entry); } else { rasPhoneBook.Entries[connectName].Update(); } RasDialer dialer = new RasDialer { EntryName = connectName, PhoneNumber = userName, AllowUseStoredCredentials = true, PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers), Credentials = new NetworkCredential(userName, password), Timeout = 1000 * 10 }; RasHandle rasHandle = dialer.Dial(); }
private static bool CreateConnector() { RasPhoneBook book = new RasPhoneBook(); try { book.Open(RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User)); if (book.Entries.Contains(ConnectorName)) { book.Entries[ConnectorName].PhoneNumber = " "; book.Entries[ConnectorName].Update(); } else { //ReadOnlyCollection<RasDevice> readOnlyCollection = RasDevice.GetDevices(); RasDevice device = RasDevice.GetDevices().First(o => o.DeviceType == RasDeviceType.PPPoE); RasEntry entry = RasEntry.CreateBroadbandEntry(ConnectorName, device); entry.PhoneNumber = " "; book.Entries.Add(entry); } try { ReadOnlyCollection <RasConnection> conList = RasConnection.GetActiveConnections(); foreach (RasConnection con in conList) { con.HangUp(); } } catch (Exception ex) { Console.WriteLine("General - Logout abnormal(Exception): " + ex); } return(true); } catch (Exception ex) { Console.WriteLine("Create a PPPoE connection fails(Exception): " + ex); return(false); } }
public static void CreateOrUpdatePPPOE(string updatePPPOEname) { RasDialer dialer = new RasDialer(); RasPhoneBook currentUserPhoneBook = new RasPhoneBook(); string path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User); currentUserPhoneBook.Open(path); if (currentUserPhoneBook.Entries.Contains(updatePPPOEname)) { currentUserPhoneBook.Entries[updatePPPOEname].PhoneNumber = " "; currentUserPhoneBook.Entries[updatePPPOEname].Update(); } else { string adds = string.Empty; ReadOnlyCollection <RasDevice> readOnlyCollection = RasDevice.GetDevices(); RasDevice device = RasDevice.GetDevices().Where(o => o.DeviceType == RasDeviceType.PPPoE).First(); RasEntry entry = RasEntry.CreateBroadbandEntry(updatePPPOEname, device); entry.PhoneNumber = " "; currentUserPhoneBook.Entries.Add(entry); } }
public Form1() { KillProcess(); InitializeComponent(); timer.Elapsed += timer_Elapsed; timer.AutoReset = false; this.Dialer.Timeout = 20000; this.Dialer.Credentials = null; this.Dialer.EapOptions = new DotRas.RasEapOptions(false, false, false); this.Dialer.HangUpPollingInterval = 0; this.Dialer.Options = new DotRas.RasDialOptions(false, false, false, false, false, false, false, false, false, false); this.Dialer.SynchronizingObject = this; //this.Dialer.StateChanged += new System.EventHandler<DotRas.StateChangedEventArgs>(this.Dialer_StateChanged); this.Dialer.DialCompleted += new System.EventHandler <DotRas.DialCompletedEventArgs>(this.Dialer_DialCompleted); string path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); //创建VPN this.AllUsersPhoneBook.Open(path); if (!this.AllUsersPhoneBook.Entries.Contains(EntryName)) { RasEntry entry = RasEntry.CreateBroadbandEntry(EntryName, RasDevice.GetDeviceByName("(PPPoE)", RasDeviceType.PPPoE)); this.AllUsersPhoneBook.Entries.Add(entry); } if (File.Exists(kwPath)) { using (StreamReader rd = new StreamReader(kwPath)) { string txt = rd.ReadToEnd(); string[] arr = txt.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string item in arr) { string[] arrs = item.Split(','); if (arrs.Length != 3) { continue; } Keyword keyword = new Keyword(); keyword.kw = arrs[0]; keyword.url = arrs[1]; keyword.total = int.Parse(arrs[2]); list.Add(keyword); } } } #region var action = new Action(delegate() { while (true) { foreach (Keyword item in list) { try { while (true) { lock (isProcessOkObj) { if (isProcessOk == false) { System.Threading.Thread.Sleep(1000); continue; } this.textBox2.Text = string.Empty; ShowMsg("whileprocess"); isProcessOk = false; break; } } keyword = item; if (keyword.showcount <= 0) { System.Threading.Thread.Sleep(1000); continue; } System.Threading.Thread.Sleep(ran.Next(3, 9) * 1000); #if !DEBUG while (true) { lock (isConnObj) { if (isConn == false) { ShowMsg("拨号中---" + keyword.kw); Dial(); System.Threading.Thread.Sleep(1000); continue; } break; } } #endif if (this.InvokeRequired) { this.Invoke(new Action(delegate() { if (wb != null && wb.IsDisposed == false) { ShowMsg("回收"); wb.Dispose(); wb = null; GC.Collect(); GC.WaitForPendingFinalizers(); IntPtr pHandle = GetCurrentProcess(); SetProcessWorkingSetSize(pHandle, -1, -1); } wb = new WebBrowser(); wb.ScriptErrorsSuppressed = true; wb.Navigating += wb_Navigating; wb.DocumentCompleted += wb_DocumentCompleted; wb.Navigate("https://www.baidu.com"); })); } } catch (Exception ex) { ShowMsg(ex.Message); } } } }); action.BeginInvoke(null, null); #endregion }
private void connect() { // connect if (textUsername.Text.Length == 0 || textPassword.Text.Length == 0) { MessageBox.Show("账号或密码信息不完整!", "Carousel", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } textUsername.Enabled = textPassword.Enabled = false; checkRemember.Enabled = checkAuto.Enabled = false; buttonConnect.Text = "连接中……"; buttonConnect.Enabled = false; notifyIcon.Text = "Carousel - 连接中"; try { RasEntry entry = RasEntry.CreateBroadbandEntry("Carousel", RasDevice.GetDeviceByName("PPPOE", RasDeviceType.PPPoE, false)); entry.FramingProtocol = RasFramingProtocol.Ppp; entry.RedialCount = 3; entry.RedialPause = 12; entry.PhoneNumber = " "; RasPhoneBook phoneBook = new RasPhoneBook(); phoneBook.Open(RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers)); phoneBook.Entries.Clear(); phoneBook.Entries.Add(entry); RasDialer dialer = new RasDialer(); dialer.EntryName = "Carousel"; dialer.PhoneNumber = ""; string username = textUsername.Text + "@wo201"; string passwd = "" + (char)(1) + textPassword.Text; dialer.Credentials = new System.Net.NetworkCredential(username, passwd); dialer.AllowUseStoredCredentials = true; dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); dialer.Timeout = 1000; handle = dialer.Dial(); connection = RasConnection.GetActiveConnectionByHandle(handle); // success connected = true; // save credentials to registry if (checkRemember.Checked) { saveCredential(textUsername.Text, textPassword.Text, true, checkAuto.Checked); } else { saveCredential("", "", false, false); } textUsername.Enabled = textPassword.Enabled = false; buttonConnect.Text = "已连接"; buttonConnect.Visible = false; buttonConnect.Enabled = false; buttonDisconnect.Visible = true; buttonDisconnect.Enabled = true; this.Hide(); notifyIcon.Text = "Carousel - 已连接"; notifyIcon.ShowBalloonTip(3000, "Carousel", "已连接", ToolTipIcon.Info); } catch (Exception ex) { // fail MessageBox.Show("连接错误,错误信息:" + ex.Message, "Carousel", MessageBoxButtons.OK, MessageBoxIcon.Error); textUsername.Enabled = textPassword.Enabled = true; checkRemember.Enabled = checkAuto.Enabled = true; buttonConnect.Text = "连接"; buttonConnect.Enabled = true; } }