public void CreateDeviceWithEmptyNameTest() { var target = RasDevice.Create(string.Empty, RasDeviceType.Modem); Assert.AreEqual(string.Empty, target.Name); Assert.AreEqual(RasDeviceType.Modem, target.DeviceType); }
public void IpSecConnectionCreate(string ipSecConnectionName, string presharedKey) { if (ipSecConnectionName == null) { throw new ArgumentNullException(nameof(ipSecConnectionName)); } if (presharedKey == null) { throw new ArgumentNullException(nameof(presharedKey)); } if (ipSecConnectionName.Length == 0) { throw new ArgumentException($"nameof(ipSecConnectionName) is empty string"); } if (presharedKey.Length == 0) { throw new ArgumentException($"nameof(presharedKey) is empty string"); } using (var rasPhoneBook = new RasPhoneBook()) { rasPhoneBook.Open(IpSecClient._phoneBookPath); var ipSecRasEntry = RasEntry.CreateVpnEntry( ipSecConnectionName, "0.0.0.0", RasVpnStrategy.L2tpOnly, RasDevice.Create(ipSecConnectionName, RasDeviceType.Vpn) ); //ipSecRasEntry.DnsAddress = System.Net.IPAddress.Parse("0.0.0.0"); //ipSecRasEntry.DnsAddressAlt = System.Net.IPAddress.Parse("0.0.0.0"); ipSecRasEntry.EncryptionType = RasEncryptionType.Require; ipSecRasEntry.EntryType = RasEntryType.Vpn; ipSecRasEntry.Options.RequireDataEncryption = true; ipSecRasEntry.Options.UsePreSharedKey = true; // used only for IPSec - L2TP/IPsec VPN ipSecRasEntry.Options.UseLogOnCredentials = false; ipSecRasEntry.Options.RequireMSChap2 = true; //rasEntry.Options.RemoteDefaultGateway = true; ipSecRasEntry.Options.SecureFileAndPrint = true; ipSecRasEntry.Options.SecureClientForMSNet = true; ipSecRasEntry.Options.ReconnectIfDropped = false; // If the entry with the same name has already been added, Add throws ArgumentException // with message: '<Entry name>' already exists in the phone book.\r\nParameter name: item" rasPhoneBook.Entries.Add(ipSecRasEntry); // RasEntry.UpdateCredentials() has to be executed after RasEntry has been added to the Phone Book. // Otherwise InvalidOperationException is thrown with message: // "The entry is not associated with a phone book." ipSecRasEntry.UpdateCredentials(RasPreSharedKey.Client, presharedKey); //ipSecRasEntry.UpdateCredentials(new System.Net.NetworkCredential("username", "password")); Console.WriteLine($"VPN connection {ipSecConnectionName} created successfully."); } }
public void CreateDeviceTest() { string name = "Test Device"; RasDeviceType deviceType = RasDeviceType.Modem; RasDevice target = RasDevice.Create(name, deviceType); Assert.AreEqual(name, target.Name); Assert.AreEqual <RasDeviceType>(deviceType, target.DeviceType); }
public void CreateDeviceTest() { var name = "Test Device"; var deviceType = RasDeviceType.Modem; var target = RasDevice.Create(name, deviceType); Assert.AreEqual(name, target.Name); Assert.AreEqual(deviceType, target.DeviceType); }
public void DeviceTest() { var expected = RasDevice.Create("PPTP", RasDeviceType.Vpn); var target = new RasConnection(); target.Device = expected; var actual = target.Device; Assert.AreEqual(expected, actual); }
public void NameTest() { var expected = "Test Device"; var target = RasDevice.Create(expected, RasDeviceType.Generic); string actual; actual = target.Name; Assert.AreEqual(expected, actual); }
public void GetDeviceByNameCaseSensitiveTest() { string name = RasDeviceTest.ValidDeviceName; RasDeviceType deviceType = RasDeviceType.Vpn; RasDevice expected = RasDevice.Create(name, deviceType); RasDevice actual = RasDevice.GetDeviceByName(name, deviceType, true); RasDeviceComparer comparer = new RasDeviceComparer(); bool target = comparer.Compare(expected, actual) == 0; Assert.IsTrue(target); }
public void DeviceTypeTest() { var name = "Test Device"; var expected = RasDeviceType.Generic; var target = RasDevice.Create(name, expected); RasDeviceType actual; actual = target.DeviceType; Assert.AreEqual(expected, actual); }
public void GetDeviceByName1TestWithExactMatchOnly() { string name = RasDeviceTest.ValidDeviceName; RasDeviceType deviceType = RasDeviceType.Vpn; bool exactMatchOnly = true; RasDevice expected = RasDevice.Create(name, deviceType); RasDevice actual; actual = RasDevice.GetDeviceByName(name, deviceType, exactMatchOnly); RasDeviceComparer comparer = new RasDeviceComparer(); bool target = comparer.Compare(expected, actual) == 0; Assert.IsTrue(target); }
private void Master(string _server) { // Connection Parameters string ServerAddress = _server; RasVpnStrategy strategy = RasVpnStrategy.SstpOnly; RasDevice device = RasDevice.Create("SSTP", RasDeviceType.Vpn); bool useRemoteDefaultGateway = true; // Create entry RasEntry entry = RasEntry.CreateVpnEntry(ConnectionName, ServerAddress, strategy, device, false); entry.DnsAddress = IPAddress.Parse("8.8.8.8"); //entry.IPAddress = IPAddress.Parse("219.100.37.219"); entry.EncryptionType = RasEncryptionType.Require; entry.EntryType = RasEntryType.Vpn; entry.Options.RequireDataEncryption = false; entry.Options.UseLogOnCredentials = false; entry.Options.RequireMSChap2 = false; entry.Options.RemoteDefaultGateway = useRemoteDefaultGateway; entry.Options.SecureFileAndPrint = true; entry.Options.SecureClientForMSNet = true; entry.Options.ReconnectIfDropped = false; //entry.Options.RegisterIPWithDns = true; // Get phone book (list of connetions) path string path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User); // Load RasPhoneBook rpb = new RasPhoneBook(); rpb.Open(path); // Check for existance of the same connection if (!rpb.Entries.Contains(entry.Name)) { rpb.Entries.Remove(entry.Name); } rpb.Entries.Add(entry); // Set user and password entry.ClearCredentials(); }
private void getPhoneEntries() { List <vpn_Entry> RemoteVpns = getRemoteVpn(); this.AllUsersPhoneBook.Open(); foreach (vpn_Entry vpn in RemoteVpns) { if (!this.AllUsersPhoneBook.Entries.Contains(vpn.Name)) { if (string.IsNullOrEmpty(vpn.vpnIP)) { continue; } RasEntry re = RasEntry.CreateVpnEntry(vpn.Name, vpn.vpnIP, RasVpnStrategy.PptpOnly, RasDevice.Create("VPN_PPTP", RasDeviceType.Vpn)); re.EncryptionType = RasEncryptionType.Optional; this.AllUsersPhoneBook.Entries.Add(re); re.UpdateCredentials(new NetworkCredential(vpn.vpnID, vpn.vpnPW)); re.Update(); } else { RasEntry re = this.AllUsersPhoneBook.Entries[vpn.Name]; IPAddress tryP = null; if (!string.IsNullOrEmpty(vpn.vpnIP)) { IPAddress.TryParse(vpn.vpnIP, out tryP); } re.IPAddress = tryP; re.PhoneNumber = re.IPAddress == null?string.Empty:re.IPAddress.ToString(); NetworkCredential nc = re.GetCredentials(); nc.UserName = vpn.vpnID; nc.Password = vpn.vpnPW; re.UpdateCredentials(nc); re.Update(); } } }
private static RasEntry CreateVpn(string vpnName, string ipAddress) { RasEntry ras = new RasEntry(vpnName) { Device = RasDevice.Create("WAN Miniport (PPTP)", RasDeviceType.Vpn), DialMode = RasDialMode.None, EncryptionType = RasEncryptionType.Optional, EntryType = RasEntryType.Vpn, FramingProtocol = RasFramingProtocol.Ppp, PhoneNumber = ipAddress, RedialCount = 2, RedialPause = 60, VpnStrategy = RasVpnStrategy.PptpOnly, Options = { DoNotNegotiateMultilink = true, IPv6RemoteDefaultGateway = true, ModemLights = true, ReconnectIfDropped = true, RemoteDefaultGateway = false, RequireDataEncryption = false, RequireEncryptedPassword = true, RequireChap = true, RequireMSChap2 = true, RequireMSEncryptedPassword = true } }; RasNetworkProtocols rasNetworkProtocols = new RasNetworkProtocols { IP = true, IPv6 = true, Ipx = false }; ras.NetworkProtocols = rasNetworkProtocols; return(ras); }
private bool VPN_Create() { //https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa377274(v=vs.85) string preSharedKey = "kit2020!^)!$)%^";//l2tp 공유기 키 RasVpnStrategy strategy = RasVpnStrategy.L2tpOnly; RasEntry vpnEntry = RasEntry.CreateVpnEntry(VPN_Name, VPN_Connection_IP, strategy, RasDevice.Create(VPN_Name, RasDeviceType.Vpn), false); // vpnEntry.Options.RequireDataEncryption = true; //데이터 암호화 vpnEntry.Options.UsePreSharedKey = true; //l2tp/ipsec vpnEntry.Options.UseLogOnCredentials = false; // 로그인 기록 저장 vpnEntry.Options.RequireMSChap = false; //Microsoft CHAP Version vpnEntry.Options.RequireMSChap2 = true; //Microsoft CHAP Version 2 (MS-CHAP v2) vpnEntry.DnsAddress = System.Net.IPAddress.Parse(VPN_Create_VirtualIP); vpnEntry.Options.RemoteDefaultGateway = false; //게이트웨이 0.0.0.0으로 RasPhoneBook phoneBook = new RasPhoneBook(); try { phoneBook.Open(); phoneBook.Entries.Add(vpnEntry); //vpn 생성 vpnEntry.UpdateCredentials(RasPreSharedKey.Client, preSharedKey); //l2tp 공유키 설정 return(true); } catch (Exception ex) { Exception FailText = ex; MessageBox.Show(string.Concat(ex.ToString(), "\n")); return(false); } }
public void AddPPTPVpnEntity(String pptpVPNName, String address) { if (!allUsersPhoneBook.Entries.Contains(pptpVPNName)) { RasEntry entry = RasEntry.CreateVpnEntry(pptpVPNName, address, RasVpnStrategy.PptpOnly, RasDevice.Create(pptpVPNName, RasDeviceType.Vpn)); allUsersPhoneBook.Entries.Add(entry); } allUsersPhoneBook.Entries[pptpVPNName].PhoneNumber = address; allUsersPhoneBook.Entries[pptpVPNName].Update(); }
public void CreateDeviceWithEmptyDeviceTypeTest() { var target = RasDevice.Create(string.Empty, string.Empty); }
public void CreateDeviceWithNullDeviceTypeTest() { var target = RasDevice.Create(string.Empty, null); }
public void AddL2TPVpnEntity(String l2tpVPNName, String address, String presharedKey) { if (!allUsersPhoneBook.Entries.Contains(l2tpVPNName)) { RasEntry entry = RasEntry.CreateVpnEntry(l2tpVPNName, address, RasVpnStrategy.L2tpOnly, RasDevice.Create(l2tpVPNName, RasDeviceType.Vpn)); allUsersPhoneBook.Entries.Add(entry); } allUsersPhoneBook.Entries[l2tpVPNName].PhoneNumber = address; allUsersPhoneBook.Entries[l2tpVPNName].Options.UsePreSharedKey = true; allUsersPhoneBook.Entries[l2tpVPNName].UpdateCredentials(RasPreSharedKey.Client, presharedKey); allUsersPhoneBook.Entries[l2tpVPNName].Update(); }
public void CreateDeviceWithNullNameTest() { RasDevice.Create(null, RasDeviceType.Modem); }