Пример #1
0
        static public void CreateConnectionEntry(BaseProxyServer ps, ProxyProtocolTypeEnum protocolType)
        {
            if (!ps.IsProtocolAvailable(protocolType))
            {
                throw new ArgumentException("Protocol " + protocolType.ToString() + " not avilable");
            }

            //http://stackoverflow.com/questions/36213393/get-connection-status-vpn-using-dotras
            // File.WriteAllText("your rasphone.pbk  path","")//Add
            RasPhoneBook rasPhoneBook1    = new RasPhoneBook();
            string       rasPhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User);//alt RasPhoneBookType.AllUsers

            rasPhoneBook1.Open(rasPhoneBookPath);

            string         deviceTypeStr = "(" + protocolType.ToString() + ")";
            RasVpnStrategy strategy      = (protocolType == ProxyProtocolTypeEnum.L2TP) ? RasVpnStrategy.L2tpOnly : RasVpnStrategy.PptpOnly;
            //alt
            //RasVpnStrategy strategy = RasVpnStrategy.Default;
            RasEntry entry = RasEntry.CreateVpnEntry(ps.GetConnectionName(), ps.Url,
                                                     strategy,
                                                     RasDevice.GetDeviceByName(deviceTypeStr, RasDeviceType.Vpn, false));

            entry.EncryptionType = ps.EncryptionType.ToEnum <RasEncryptionType>();
            if (protocolType == ProxyProtocolTypeEnum.L2TP && !string.IsNullOrEmpty(ps.GetProxyProvider().UserPresharedKey))
            {
                entry.Options.UsePreSharedKey = true;
            }
            rasPhoneBook1.Entries.Add(entry);
            if (protocolType == ProxyProtocolTypeEnum.L2TP && !string.IsNullOrEmpty(ps.GetProxyProvider().UserPresharedKey))
            {
                entry.UpdateCredentials(RasPreSharedKey.Client, ps.GetProxyProvider().UserPresharedKey);
            }

            if (!string.IsNullOrEmpty(ps.GetProxyProvider().VPNLogin))
            {
                //entry.UpdateCredentials(new System.Net.NetworkCredential(ps.JProxyProvider.VPNLogin, ps.JProxyProvider.VPNPassword), false);
            }
        }
Пример #2
0
 public bool IsProtocolAvailable(ProxyProtocolTypeEnum prot)
 {
     return(ModelHelper.IsContainsDict(AvailableProtocols, prot));
 }