コード例 #1
0
        public void IpSecConnectionRemove(string ipSecConnectionName)
        {
            if (ipSecConnectionName == null)
            {
                throw new ArgumentNullException(nameof(ipSecConnectionName));
            }

            if (ipSecConnectionName.Length == 0)
            {
                throw new ArgumentException($"nameof(ipSecConnectionName) is empty string");
            }

            using (var rasPhoneBook = new RasPhoneBook())
            {
                rasPhoneBook.Open(IpSecClient._phoneBookPath);

                var ipSecRasEntry = IpSecClient.RasEntryFindByName(rasPhoneBook, ipSecConnectionName);

                if (ipSecRasEntry.Remove())
                {
                    Console.WriteLine($"VPN connection {ipSecConnectionName} removed successfully.");
                }
                else
                {
                    throw new Exception("RasEntry.Remove() failed.");
                }
            }
        }
コード例 #2
0
        private RasEntry IpSecRasEntryGet(string ipSecConnectionName)
        {
            RasEntry ipSecRasEntry = null;

            using (var rasPhoneBook = new RasPhoneBook())
            {
                rasPhoneBook.Open(IpSecClient._phoneBookPath);

                ipSecRasEntry = IpSecClient.RasEntryFindByName(rasPhoneBook, ipSecConnectionName);
            }

            return(ipSecRasEntry);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: BojanKomazec/IpSec
 private static void ConnectionsList()
 {
     try
     {
         using (var ipSecClient = new IpSecClient())
         {
             ipSecClient.ConnectionsList();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
コード例 #4
0
        public void ConnectionsList()
        {
            using (var rasPhoneBook = new RasPhoneBook())
            {
                // If RasPhoneBookType.AllUsers and code is executed with non-admin privileges:
                // System.UnauthorizedAccessException:
                // Access to the path 'C:\ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk' is denied.
                rasPhoneBook.Open(IpSecClient._phoneBookPath);

                // Diagnostics
                Console.WriteLine("VPN connections: ");
                IpSecClient.PhoneBookEntriesList(rasPhoneBook);
                Console.WriteLine();
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: BojanKomazec/IpSec
        private static void IpSecConnectionCreate()
        {
            try
            {
                Console.Write("IPSec connection name: ");
                var ipSecConnectionName = Console.ReadLine();

                Console.Write("Preshared key: ");
                var presharedKey = Console.ReadLine();

                using (var ipSecClient = new IpSecClient())
                {
                    ipSecClient.IpSecConnectionCreate(ipSecConnectionName, presharedKey);
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: BojanKomazec/IpSec
        private static void IpSecConnectionRemove()
        {
            try
            {
                Console.Write("IPSec connection name: ");
                var ipSecConnectionName = Console.ReadLine();

                using (var ipSecClient = new IpSecClient())
                {
                    ipSecClient.IpSecConnectionRemove(ipSecConnectionName);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: BojanKomazec/IpSec
        private static async Task IpSecConnectionDisconnectionDemoAsync()
        {
            using (var ipSecClient = new IpSecClient())
            {
                try
                {
                    Console.Write("IPSec connection name: ");
                    var ipSecConnectionName = Console.ReadLine();

                    Console.Write("IPSec Server IP address: ");
                    var ipAddress = Console.ReadLine();

                    Console.Write("Username: "******"Password: "******"username", username},
                        {"password", password},
                        {"IpSecConnectionName", ipSecConnectionName}
                    };

                    Console.WriteLine("Press <ENTER> to Connect...");
                    Console.ReadLine();

                    await ipSecClient.ConnectAsync(vpnEndPoint, parameters, CancellationToken.None);
                    Program.PublicIpAddressVerify();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Console.WriteLine("Press <ENTER> to Disconnect...");
                Console.ReadLine();

                try
                {
                    await ipSecClient.DisconnectAsync();
                    Program.PublicIpAddressVerify();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }