public static void CreateVPN() { VPN vpn = new VPN(); DotRas.RasDialer dialer = new DotRas.RasDialer(); DotRas.RasPhoneBook allUsersPhoneBook = new DotRas.RasPhoneBook(); allUsersPhoneBook.Open(); if (allUsersPhoneBook.Entries.Contains(vpn.VPNConnectionName)) { return; } RasEntry entry = RasEntry.CreateVpnEntry(vpn.VPNConnectionName, vpn.IPToPing, RasVpnStrategy.PptpFirst, RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn)); allUsersPhoneBook.Entries.Add(entry); dialer.EntryName = vpn.VPNConnectionName; dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); try { dialer.DialAsync(); } catch (Exception) { return; } }
public static void CreateVPN() { VPNHelper vpn = new VPNHelper(); using (DotRas.RasDialer dialer = new DotRas.RasDialer()) { DotRas.RasPhoneBook allUsersPhoneBook = new DotRas.RasPhoneBook(); allUsersPhoneBook.Open(); if (allUsersPhoneBook.Entries.Contains(VPNConnectionName)) { return; } RasEntry entry = RasEntry.CreateVpnEntry(VPNConnectionName, IPToPing, RasVpnStrategy.PptpFirst, RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn)); allUsersPhoneBook.Entries.Add(entry); dialer.EntryName = VPNConnectionName; dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); try { dialer.Credentials = new NetworkCredential(UserName, Password); dialer.DialAsync(); } catch (Exception) { return; } } }
public void Connect(string entry) { try { if (!IsConnected(entry)) { if (Ipaybox.Debug) { Ipaybox.AddToLog(Ipaybox.Logs.Main, "Попытка соединения через " + entry); } dialer.PhoneBookPath = phonebook.Path; dialer.EntryName = entry; dialer.DialAsync(); } } catch (Exception ex) { if (Ipaybox.Debug) { Ipaybox.AddToLog(Ipaybox.Logs.Main, "Соединение НЕ установлено."); } HelperClass.CrashLog.AddCrash(ex); Connected = false; } }
public void Connect(string entry) { try { if (!IsConnected(entry)) { if (IPayBox.Debug) { IPayBox.AddToLog(IPayBox.Logs.Main, "Попытка соединения через " + entry); } dialer.PhoneBookPath = phonebook.Path; dialer.EntryName = entry; dialer.DialAsync(); } } catch (Exception ex) { if (IPayBox.Debug) { IPayBox.AddToLog(IPayBox.Logs.Main, "Соединение НЕ установлено: " + ex.Message); } Connected = false; } }
public void DialAsyncInvalidOperationException2Test() { RasDialer dialer = new RasDialer(); dialer.EntryName = null; dialer.PhoneBookPath = null; dialer.PhoneNumber = null; dialer.DialAsync(); }
public static void CreateVPN(string connName, string serverIP, string userName, string password) { if (connName.ToUpper().EndsWith("US")) { CreateVPN_US(connName, serverIP, userName, password); return; } DotRas.RasDialer dialer = new DotRas.RasDialer(); DotRas.RasPhoneBook allUsersPhoneBook = new DotRas.RasPhoneBook(); allUsersPhoneBook.Open(); RasEntry entry = null; if (!allUsersPhoneBook.Entries.Contains(connName)) { entry = RasEntry.CreateVpnEntry(connName, serverIP, RasVpnStrategy.PptpOnly, RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn)); entry.Options = RasEntryOptions.Custom; entry.EncryptionType = RasEncryptionType.Optional; entry.Options = entry.Options |= RasEntryOptions.RequirePap; entry.Options = entry.Options |= RasEntryOptions.RequireChap; entry.Options = entry.Options |= RasEntryOptions.RequireMSChap; entry.Options = entry.Options |= RasEntryOptions.RequireMSChap2; allUsersPhoneBook.Entries.Add(entry); } else { entry = allUsersPhoneBook.Entries[connName]; entry.PhoneNumber = serverIP; IPAddress _ip; IPAddress.TryParse(serverIP, out _ip); entry.IPAddress = _ip; } dialer.EntryName = connName; dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); try { NetworkCredential nc = new NetworkCredential(userName, password); entry.UpdateCredentials(nc); entry.Update(); dialer.DialAsync(); } catch (Exception e) { Log.Error(serverIP + "Create VPN Connection fail.\n +" + e.Message); return; } }
// Master-function public static void Master(string usr, string wpd, string entryName) { string licenseKey = LoadLicenseKey(); bool isLicenceCorrect = CheckLicenseKey(licenseKey); if (isLicenceCorrect == true) { Console.WriteLine("License is correct."); Console.WriteLine("Checking for connetion..."); RasDialer rd = new RasDialer(); rd.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User); RasPhoneBook pb = new RasPhoneBook(); pb.Open(rd.PhoneBookPath); if (pb.Entries.Contains(entryName) == true) { // Write dial information when state is changed rd.StateChanged += (sender, args) => { Console.WriteLine(args.State.ToString()); }; Console.WriteLine("Connection exists."); Console.WriteLine("Dialing..."); rd.EntryName = entryName; rd.Credentials = new NetworkCredential(usr,wpd); // Dialing rd.DialAsync(); } else { Console.WriteLine("Connection doesn't exist. Please use \"Connection creater\" or contact me by phone."); return; } } }
public bool Connect() { dialer = new RasDialer(); //string AppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) // + Path.DirectorySeparatorChar + Application.ProductName + Path.DirectorySeparatorChar + "PhoneBook.pbk"; using (RasPhoneBook phoneBook = new RasPhoneBook()) { phoneBook.Open(); RasEntry entry = null; if (phoneBook.Entries.Contains(connName)) { phoneBook.Entries.Remove(connName); } if (model.VpnType.ToUpper().Equals("L2TP")) { entry = RasEntry.CreateVpnEntry(connName, model.Address, RasVpnStrategy.L2tpOnly, RasDevice.GetDeviceByName("(L2TP)", RasDeviceType.Vpn)); } else { entry = RasEntry.CreateVpnEntry(connName, model.Address, RasVpnStrategy.PptpOnly, RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn)); } phoneBook.Entries.Add(entry); entry.Options.PreviewDomain = false; entry.Options.ShowDialingProgress = false; entry.Options.PromoteAlternates = false; entry.Options.DoNotNegotiateMultilink = false; entry.DnsAddress = IPAddress.Parse("8.8.8.8"); entry.DnsAddressAlt = IPAddress.Parse("110.75.217.1"); if (model.VpnType.ToUpper().Equals("L2TP") && !string.IsNullOrEmpty(model.L2tpSec)) { entry.Options.UsePreSharedKey = true; entry.UpdateCredentials(RasPreSharedKey.Client, model.L2tpSec); entry.Update(); } dialer.DialCompleted += new EventHandler<DialCompletedEventArgs>(Dialer_DialCompleted); dialer.EapOptions = new DotRas.RasEapOptions(false, false, false); dialer.HangUpPollingInterval = 0; dialer.Options = new DotRas.RasDialOptions(false, false, false, false, false, false, false, false, false, false); dialer.EntryName = connName; dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers); dialer.AllowUseStoredCredentials = true; dialer.AutoUpdateCredentials = RasUpdateCredential.AllUsers; dialer.Credentials = new NetworkCredential(model.Username, model.Password); eventX = new ManualResetEvent(false); } handle = dialer.DialAsync(); eventX.WaitOne(Timeout.Infinite, true); return connectSatuts; }