Exemple #1
0
        public static void Test()
        {
            NicInterface.PrintAllNetworkInterface();
            Console.Read();
            ShowNetworkInfo();
            Console.Read();
            Ip4RouteTable.RoutePrint(Ip4RouteTable.GetRouteTable());
            Console.Read();

            Ip4RouteEntry routeEntry = new Ip4RouteEntry
            {
                DestinationIP  = IPAddress.Parse("202.0.0.0"),
                SubnetMask     = IPAddress.Parse("255.0.0.0"),
                GatewayIP      = IPAddress.Parse("10.33.55.1"),
                InterfaceIndex = 11
            };

            //Ip4RouteTable.CreateRoute(routeEntry);
            Ip4RouteTable.DeleteRoute(42);
            Ip4RouteTable.CreateRoute("202.0.0.0", "255.0.0.0", 42, 100);
            Console.Read();
            Ip4RouteTable.RoutePrint(Ip4RouteTable.GetRouteTable());
            Console.Read();
            //Ip4RouteTable.DeleteRoute(routeEntry);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            try
            {
                //Get Parameter
                int interfaceIndex = 0;
                if (args.Count() > 0)
                {
                    interfaceIndex = Int32.Parse(args[0]);
                }


                //Print all the Network adaptors
                NicInterface.PrintAllNetworkInterface();
                //Print the Routing Table
                Ip4RouteTable.RoutePrint();

                if (!Ip4RouteTable.InterfaceIndexExists(interfaceIndex))
                {
                    Console.WriteLine("InterfaceIndex '{0}' does not exists.", interfaceIndex);
                    return;
                }

                //Determine if the Route Table has multiple 1.1.1.1 routes, indicating a VPN is active
                if (!Ip4RouteTable.RouteExists("1.1.1.1"))
                {
                    return;
                }
                //Demostrate Deleting routes and Adding routes

                Ip4RouteEntry routeEntry = Ip4RouteTable.GetRouteEntry("1.1.1.1").First();
                //NetworkAdaptor na = NicInterface.GetNetworkAdaptor(interfaceIndex);
                if (routeEntry != null && routeEntry.GatewayIP.ToString().Length > 0)
                {
                    Console.WriteLine("Deleting VPN existing routes.");
                    Ip4RouteTable.DeleteRoute(interfaceIndex);
                    Ip4RouteTable.DeleteRoute("202.0.0.0");

                    Console.WriteLine("Adding VPN new route.");
                    Ip4RouteTable.CreateRoute("202.0.0.0", "255.0.0.0", interfaceIndex, 100);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace.ToString());
                throw;
            }
        }