Пример #1
0
        public bool Connect(VPNServer server)
        {
            Disconnect();
            current_server = server;
            try
            {
                using (RasPhoneBook phonebook = new RasPhoneBook())
                {
                    phonebook.Open(VPNSettings.VPNRasPhoneBook);

                    string name = VPNSettings.ConnectionEntry;

                    var       devices = RasDevice.GetDevices();
                    RasDevice device  = null;

                    foreach (RasDevice modem in devices)
                    {
                        if (modem.Name.ToLower().Contains("(pptp)"))
                        {
                            device = modem;
                            break;
                        }
                    }

                    RasEntry entry = RasEntry.CreateVpnEntry(name, server.ipinfo.ip, RasVpnStrategy.Default, device);

                    phonebook.Entries.Clear();
                    phonebook.Entries.Add(entry);
                }

                RasDialer dialer = new RasDialer();
                dialer.EntryName     = VPNSettings.ConnectionEntry;
                dialer.PhoneBookPath = VPNSettings.VPNRasPhoneBook;
                dialer.Credentials   = server.credentials;

                dialer.DialAsync();


                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                return(false);
            }
        }
Пример #2
0
        public void GetVPNServerList()
        {
            string Filename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".csv";

            using (WebClient client = new WebClient())
            {
                client.DownloadFile("http://www.vpngate.net/api/iPhone", Filename);
            }

            using (TextFieldParser parser = new TextFieldParser(Filename))
            {
                parser.TextFieldType = FieldType.Delimited;
                parser.SetDelimiters(",");
                while (!parser.EndOfData)
                {
                    VPNServer server = new VPNServer(parser.ReadFields());
                }
            }
        }
Пример #3
0
 public VPNConnection(VPNServer server)
 {
     Connect(server);
 }