Пример #1
0
        public override TrafficSplitterRule Create(NameValueItem nviConfigurationRoot)
        {
            IPAddressRule ipaRule = new IPAddressRule();

            ipaRule.Action = ConvertToAction(nviConfigurationRoot.GetChildsByName("action")[0]);

            if (nviConfigurationRoot.ContainsChildItem("address"))
            {
                ipaRule.Address = IPAddress.Parse(nviConfigurationRoot["address"][0].Value);
            }
            if (nviConfigurationRoot.ContainsChildItem("wildcard"))
            {
                ipaRule.Wildcard = Subnetmask.Parse(nviConfigurationRoot["wildcard"][0].Value);
            }

            if (nviConfigurationRoot.ContainsChildItem("destinationAddress"))
            {
                ipaRule.Destination = IPAddress.Parse(nviConfigurationRoot["destinationAddress"][0].Value);
            }
            if (nviConfigurationRoot.ContainsChildItem("sourceAddress"))
            {
                ipaRule.Source = IPAddress.Parse(nviConfigurationRoot["sourceAddress"][0].Value);
            }

            if (nviConfigurationRoot.ContainsChildItem("destinationWildcard"))
            {
                ipaRule.DestinationWildcard = Subnetmask.Parse(nviConfigurationRoot["destinationWildcard"][0].Value);
            }
            if (nviConfigurationRoot.ContainsChildItem("sourceWildcard"))
            {
                ipaRule.SourceWildcard = Subnetmask.Parse(nviConfigurationRoot["sourceWildcard"][0].Value);
            }

            return(ipaRule);
        }
Пример #2
0
        /// <summary>
        /// Converts an array of name value items to an array of subnetmasks
        /// </summary>
        /// <param name="strString">The name value item which should be converted</param>
        /// <returns>An array of subnetmasks</returns>
        public static Subnetmask[] ConvertToSubnetmask(NameValueItem[] strString)
        {
            Subnetmask[] sam = new Subnetmask[strString.Length];

            for (int iC1 = 0; iC1 < strString.Length; iC1++)
            {
                sam[iC1] = Subnetmask.Parse(strString[iC1].Value);
            }

            return(sam);
        }
Пример #3
0
        static void Main(string[] args)
        {
            //Query all interfaces
            WinPcapInterface[] arWpc = EthernetInterface.GetAllPcapInterfaces();

            //Create handler classes
            Router          rRouter    = new Router();
            TrafficSplitter tsSplitter = new TrafficSplitter();

            //Start handlers
            rRouter.Start();
            tsSplitter.Start();

            //Let the router forward traffic from the interfaces to the traffic splitter
            rRouter.OutputHandler = tsSplitter;
            //Let the traffic splitter forward received traffic back to the router
            tsSplitter.OutputHandler = rRouter;

            //Create the properties of the routing entry
            IPAddress  ipaDestination = IPAddress.Parse("0.0.0.0");
            IPAddress  ipaGateway     = IPAddress.Parse("192.168.0.1");
            Subnetmask smMask         = Subnetmask.Parse("0.0.0.0");
            int        iMetric        = 10;

            //Create the routing entry
            RoutingEntry rEntry = new RoutingEntry(ipaDestination, ipaGateway, iMetric, smMask, RoutingEntryOwner.UserStatic);

            //Add some event handlers
            rRouter.FrameDropped    += new EventHandler(rRouter_FrameDropped);
            rRouter.FrameForwarded  += new EventHandler(rRouter_FrameForwarded);
            rRouter.FrameReceived   += new EventHandler(rRouter_FrameReceived);
            rRouter.ExceptionThrown += new TrafficHandler.ExceptionEventHandler(rRouter_ExceptionThrown);

            //Create a list for the interfaces
            List <EthernetInterface> wpcInterfaces = new List <EthernetInterface>();

            //Foreach WinPcapInterface of this host
            foreach (WinPcapInterface wpc in arWpc)
            {
                //Create a new interface handler and start it
                EthernetInterface ipInterface = new EthernetInterface(wpc);
                ipInterface.Start();

                //Then add it to the router and to our list
                wpcInterfaces.Add(ipInterface);
                rRouter.AddInterface(ipInterface);
            }

            Console.WriteLine("Loading complete...");

            //Run until 'x' is pressed
            while (Console.ReadKey().Key != ConsoleKey.X)
            {
                ;
            }

            //Start the cleanup process for all handlers
            rRouter.Cleanup();
            tsSplitter.Cleanup();

            //Start the cleanup process for all interfaces
            foreach (EthernetInterface ipInterface in wpcInterfaces)
            {
                ipInterface.Cleanup();
            }

            //Stop all handlers
            rRouter.Stop();
            tsSplitter.Stop();

            //Stop all interfaces
            foreach (EthernetInterface ipInterface in wpcInterfaces)
            {
                ipInterface.Stop();
            }
        }
        /// <summary>
        /// Returns all routes from the operating system
        /// </summary>
        /// <returns>All routes from the operating system</returns>
        public static RoutingEntry[] GetOSRoutes()
        {
            List<RoutingEntry> lReEntry = new List<RoutingEntry>(); 
            
            try
            {
                ManagementClass mcConf = new ManagementClass("Win32_IP4RouteTable");

                ManagementObjectCollection acConfs = mcConf.GetInstances();

                foreach (ManagementObject moObject in acConfs)
                {
                    lReEntry.Add(new RoutingEntry(IPAddress.Parse((string)moObject["Destination"]), IPAddress.Parse((string)moObject["NextHop"]), (int)moObject["Metric1"], Subnetmask.Parse((string)moObject["Mask"]), RoutingEntryOwner.System)); 
                }
            }
            catch (Exception) { }

            return lReEntry.ToArray();
        }
Пример #5
0
        static void Main(string[] args)
        {
            //Query all interfaces
            WinPcapInterface[] arWpc = EthernetInterface.GetAllPcapInterfaces();

            //Create handler classes
            Router          rRouter     = new Router();
            TrafficSplitter tsSplitter  = new TrafficSplitter();
            LibCapDumper    lcpDumper   = new LibCapDumper();
            NetMap          nmMap       = new NetMap();
            WANEmulator     wanEmulator = new WANEmulator();

            //Start handlers
            rRouter.Start();
            tsSplitter.Start();
            lcpDumper.Start();
            nmMap.Start();
            wanEmulator.Start();

            //Let the router forward traffic from the interfaces to the traffic splitter
            rRouter.OutputHandler = tsSplitter;
            //Let the traffic splitter forward received traffic to the WAN emulator
            tsSplitter.OutputHandler = wanEmulator;
            //Let the WAN emulator forward received traffic back to the router
            wanEmulator.OutputHandler = rRouter;
            //Let the traffic splitter clone each frame and send it to the traffic dumper and the NetMap
            tsSplitter.AddTrafficAnalyzer(nmMap);
            tsSplitter.AddTrafficAnalyzer(lcpDumper);


            //Create the properties of the routing entry
            IPAddress  ipaDestination = IPAddress.Parse("0.0.0.0");
            IPAddress  ipaGateway     = IPAddress.Parse("192.168.0.1");
            Subnetmask smMask         = Subnetmask.Parse("0.0.0.0");
            int        iMetric        = 10;

            //Create the routing entry
            RoutingEntry rEntry = new RoutingEntry(ipaDestination, ipaGateway, iMetric, smMask, RoutingEntryOwner.UserStatic);

            //Set traffic dumper properties
            lcpDumper.StartLogging(Path.Combine(System.Environment.CurrentDirectory, "Dump " + DateTime.Now.ToLongDateString()), false);

            //Add some event handlers
            rRouter.FrameDropped         += new EventHandler(rRouter_FrameDropped);
            rRouter.FrameForwarded       += new EventHandler(rRouter_FrameForwarded);
            rRouter.FrameReceived        += new EventHandler(rRouter_FrameReceived);
            rRouter.ExceptionThrown      += new TrafficHandler.ExceptionEventHandler(rRouter_ExceptionThrown);
            nmMap.HostInformationChanged += new NetMap.HostChangedEventHandler(nmMap_HostInformationChanged);

            //Create a list for the interfaces
            List <EthernetInterface> wpcInterfaces = new List <EthernetInterface>();

            //Foreach WinPcapInterface of this host
            foreach (WinPcapInterface wpc in arWpc)
            {
                //Create a new interface handler and start it
                EthernetInterface ipInterface = new EthernetInterface(wpc);
                ipInterface.Start();

                //Then add it to the router and to our list
                wpcInterfaces.Add(ipInterface);
                rRouter.AddInterface(ipInterface);
            }

            Console.WriteLine("Loading complete...");

            //Run until 'x' is pressed
            while (Console.ReadKey().Key != ConsoleKey.X)
            {
                ;
            }

            //Start the cleanup process for all handlers
            rRouter.Cleanup();
            tsSplitter.Cleanup();
            lcpDumper.Cleanup();
            nmMap.Cleanup();
            wanEmulator.Cleanup();

            //Start the cleanup process for all interfaces
            foreach (EthernetInterface ipInterface in wpcInterfaces)
            {
                ipInterface.Cleanup();
            }

            //Stop all handlers
            rRouter.Stop();
            tsSplitter.Stop();
            lcpDumper.Stop();
            nmMap.Stop();
            wanEmulator.Stop();

            //Stop all interfaces
            foreach (EthernetInterface ipInterface in wpcInterfaces)
            {
                ipInterface.Stop();
            }
        }