Exemplo n.º 1
0
        private void createVpnEntry(string sVpnIp)
        {
            AllUsersPhoneBook.Open(Dialer.PhoneBookPath);

            if (this.AllUsersPhoneBook.Entries.Contains(sEntryName))
            {
                //todo
                this.AllUsersPhoneBook.Entries[sEntryName].PhoneNumber = sVpnIp;
            }
            else
            {
                try
                {
                    RasEntry entry = RasEntry.CreateVpnEntry(sEntryName, sVpnIp, RasVpnStrategy.L2tpOnly,
#pragma warning disable CS0618 // 类型或成员已过时
                                                             device: RasDevice.GetDeviceByName("(L2TP)", RasDeviceType.Vpn));
#pragma warning restore CS0618 // 类型或成员已过时
                    entry.EncryptionType = RasEncryptionType.Optional;

                    this.AllUsersPhoneBook.Entries.Add(entry);
                }
                catch (Exception ex)
                {
                    tMessage.AppendText(ex.ToString());
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Occurs when the user clicks the Create Entry button.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">An <see cref="System.EventArgs"/> containing event data.</param>
        private void CreateEntryButton_Click(object sender, EventArgs e)
        {
            try
            {
                // This opens the phonebook so it can be used. Different overloads here will determine where the phonebook is opened/created.
                AllUsersPhoneBook.Open(PHONE_BOOK_PATH);

                // Create the entry that will be used by the dialer to dial the connection. Entries can be created manually, however the static methods on
                // the RasEntry class shown below contain default information matching that what is set by Windows for each platform.
                var rasDevice = RasDevice.GetDevices().FirstOrDefault(_ => _.Name.Contains("(PPTP)") && _.DeviceType == RasDeviceType.Vpn);
                var entry     = RasEntry.CreateVpnEntry(EntryName, IPAddress.Loopback.ToString(), RasVpnStrategy.Default, rasDevice);

                // Add the new entry to the phone book.
                AllUsersPhoneBook.Entries.Add(entry);
            }
            catch (Exception ex)
            {
                StatusTextBox.AppendText(ex.ToString());
            }
        }
Exemplo n.º 3
0
        private bool CreateVpnEntry(string sVpnIp)
        {
            AllUsersPhoneBook.Open();

            if (this.AllUsersPhoneBook.Entries.Contains(sEntryName))
            {
                var ipInfo = GetVpnIP();
                if (ipInfo != null)
                {
                    DoMessage(string.Format("{0} 已经存在到同一个服务器的连接!", DateTime.Now.ToString()));
                    return(false);
                }

                this.AllUsersPhoneBook.Entries[sEntryName].PhoneNumber = sVpnIp;
            }
            else
            {
                try
                {
                    var deviceList = RasDevice.GetDevices();
                    var vpnDevice  = deviceList.Where(d => d.DeviceType == RasDeviceType.Vpn && d.Name.Contains("(PPTP)")).FirstOrDefault();
                    if (vpnDevice == null)
                    {
                        DoMessage(string.Format("{0} 无可用VPN端口,请尝试执行[netsh winsock reset]进行修复!", DateTime.Now.ToString()));
                        return(false);
                    }

                    RasEntry entry = RasEntry.CreateVpnEntry(sEntryName, sVpnIp, RasVpnStrategy.PptpOnly, vpnDevice, false);
                    entry.EncryptionType = RasEncryptionType.Optional;

                    this.AllUsersPhoneBook.Entries.Add(entry);
                }
                catch (Exception ex)
                {
                    DoMessage(string.Format("{0} {1}", DateTime.Now.ToString(), ex.ToString()));
                }
            }

            return(true);
        }