private void CreateOrUpdateVPNEntry(string ip)
 {
     Log.debug(TAG, "CreateOrUpdateVPNEntry ip:" + ip);
     try
     {
         RasEntry entry = null;
         if (allUsersPhoneBook.Entries.Contains(VPNNAME))
         {
             entry = allUsersPhoneBook.Entries[VPNNAME];
             entry.EncryptionType = RasEncryptionType.Optional;
             entry.PhoneNumber    = ip;
             IPAddress _ip;
             IPAddress.TryParse(ip, out _ip);
             entry.IPAddress = _ip;
             entry.Options.UsePreSharedKey = true;
             entry.UpdateCredentials(RasPreSharedKey.Client, "123456");
             entry.Update();
         }
         else
         {
             entry = RasEntry.CreateVpnEntry(VPNNAME, ip, RasVpnStrategy.L2tpOnly, RasDevice.GetDeviceByName("(L2TP)", RasDeviceType.Vpn));
             entry.EncryptionType          = RasEncryptionType.Optional;
             entry.Options.UsePreSharedKey = true;
             allUsersPhoneBook.Entries.Add(entry);
             entry.UpdateCredentials(RasPreSharedKey.Client, "123456");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("创建VPN失败!error msg:" + ex.ToString());
         Log.debug(TAG, "CreateOrUpdateVPNEntry error:" + ex.ToString());
     }
 }
示例#2
0
        /// <summary>
        /// 创建或更新一个VPN连接(指定VPN名称,及IP)
        /// </summary>
        public void CreateOrUpdateVPN(string updateVPNname, string updateVPNip)
        {
            Log.debug(TAG, "CreateOrUpdateVPN");
            RasDialer    dialer            = new RasDialer();
            RasPhoneBook allUsersPhoneBook = new RasPhoneBook();

            allUsersPhoneBook.Open();

            RasEntry entry = null;

            if (allUsersPhoneBook.Entries.Contains(updateVPNname))
            {
                entry = allUsersPhoneBook.Entries[updateVPNname];
                entry.EncryptionType = RasEncryptionType.Optional;
                entry.PhoneNumber    = updateVPNip;
                IPAddress _ip;
                IPAddress.TryParse(updateVPNip, out _ip);
                entry.IPAddress = _ip;
                entry.Options.UsePreSharedKey = true;
                entry.UpdateCredentials(RasPreSharedKey.Client, "123456");
                entry.Update();
            }
            else
            {
                entry = RasEntry.CreateVpnEntry(updateVPNname, updateVPNip, RasVpnStrategy.L2tpOnly, RasDevice.GetDeviceByName("(L2TP)", RasDeviceType.Vpn));
                entry.EncryptionType          = RasEncryptionType.Optional;
                entry.Options.UsePreSharedKey = true;
                allUsersPhoneBook.Entries.Add(entry);
                entry.UpdateCredentials(RasPreSharedKey.Client, "123456");
            }
        }
示例#3
0
 public static bool UpdateDestinationHost(this RasEntry entry, string server)
 {
     //using (var pbk = new RasPhoneBook())
     //{
     //    pbk.Open(RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User));
     //    var me = pbk.Entries[entry.ent];
     //    me.PhoneNumber = server;
     //    return me.Update();
     //}
     entry.PhoneNumber = server;
     return(entry.Update());
 }
示例#4
0
        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();
                }
            }
        }
示例#5
0
        //This creates the M5 phonebook with all the necessary parameters in it
        private static void CreateRas(string phonebookPath)
        {
            DotRas.RasPhoneBook pb = new DotRas.RasPhoneBook();
            pb.Open(phonebookPath);
            RasDevice rasDevice = RasDevice.GetDevices().Where(P => P.DeviceType == RasDeviceType.Modem && P.Name.ToUpper().StartsWith("M5-")).FirstOrDefault();

            if (rasDevice == null)
            {
                return;
            }

            RasEntry entry = pb.Entries.Where(p => p.Name == "M5_1").FirstOrDefault();

            if (entry == null)
            {
                entry = RasEntry.CreateDialUpEntry("M5_1", "0", rasDevice);
            }

            entry.FramingProtocol = RasFramingProtocol.Ppp;
            entry.EncryptionType  = RasEncryptionType.None;
            entry.FrameSize       = 0;

            entry.Options.DisableLcpExtensions    = true;
            entry.Options.DisableNbtOverIP        = true;
            entry.Options.DoNotNegotiateMultilink = true;
            entry.Options.DoNotUseRasCredentials  = true;
            entry.Options.Internet            = false;
            entry.Options.IPHeaderCompression = false;
            entry.Options.ModemLights         = true;
            entry.Options.NetworkLogOn        = false;

            entry.Options.PreviewDomain       = false;
            entry.Options.PreviewPhoneNumber  = false;
            entry.Options.PreviewUserPassword = false;
            entry.Options.PromoteAlternates   = false;

            entry.Options.ReconnectIfDropped   = false;
            entry.Options.RemoteDefaultGateway = false;

            entry.Options.RequireChap                = false;
            entry.Options.RequireDataEncryption      = false;
            entry.Options.RequireEap                 = false;
            entry.Options.RequireEncryptedPassword   = false;
            entry.Options.RequireMSChap              = false;
            entry.Options.RequireMSChap2             = false;
            entry.Options.RequireMSEncryptedPassword = false;
            entry.Options.RequirePap                 = false;
            entry.Options.RequireSpap                = false;
            entry.Options.RequireWin95MSChap         = false;

            entry.Options.SecureClientForMSNet = true;
            entry.Options.SecureFileAndPrint   = true;
            entry.Options.SecureLocalFiles     = true;

            entry.Options.SharedPhoneNumbers  = false;
            entry.Options.SharePhoneNumbers   = false;
            entry.Options.ShowDialingProgress = false;

            entry.Options.SoftwareCompression = false;
            entry.Options.TerminalAfterDial   = false;
            entry.Options.TerminalBeforeDial  = false;

            entry.Options.UseCountryAndAreaCodes  = false;
            entry.Options.UseGlobalDeviceSettings = false;
            entry.Options.UseLogOnCredentials     = false;
            entry.Options.UsePreSharedKey         = false;

            if (pb.Entries.Contains(entry.Name))
            {
                entry.Update();
            }
            else
            {
                pb.Entries.Add(entry);
            }
        }