Пример #1
0
        public bool AreAllSettingsValidAndPresent()
        {
            LogThis(LogLevel.Debug, "-> Check if all settings are valid and present ...");

            bool isValid = true; //assumption

            if (AutoEnableSwitcherOnStartup == null)
            {
                isValid = false;
            }
            else if (AutoEnableSwitcherOnStartup == null)
            {
                isValid = false;
            }
            else if (ShowCurrentConnectionTypeInSystemTray == null)
            {
                isValid = false;
            }
            else if (EthernetInterface == null || EthernetInterface.IsValid() == false)
            {
                isValid = false;
            }
            else if (WifiInterface == null || WifiInterface.IsValid() == false)
            {
                isValid = false;
            }

            LogThis(LogLevel.Debug, $"Checking done - All settings are valid and present: {isValid}");

            return(isValid);
        }
        private void OnEthernetInterfaceChanged(object sender, EventArgs e)
        {
            EthernetInterface iface = (EthernetInterface)EthernetInterfaceListBox.SelectedItem;
            bool isNetHub           = (iface.Name == NethubInterface.NETHUB_NAME);

            txtNetHubHost.Enabled = isNetHub;
            numNetHubPort.Enabled = isNetHub;
        }
Пример #3
0
        private void PopulateNetworkAdapterList()
        {
            //
            // Populate the list with the interfaces available on the machine, if any.
            //
            EthernetInterfaceListBox.Enabled = Configuration.HostRawEthernetInterfacesAvailable;
            EthernetInterfaceListBox.Items.Clear();


            // Add the "Use no interface" option
            EthernetInterfaceListBox.Items.Add(
                new EthernetInterface("None", "No network adapter"));

            // Add all interfaces that PCAP knows about.

            if (Configuration.HostRawEthernetInterfacesAvailable)
            {
                if (Configuration.Platform == PlatformType.Windows)
                {
                    foreach (WinPcapDevice device in CaptureDeviceList.Instance)
                    {
                        if (!string.IsNullOrWhiteSpace(device.Interface.FriendlyName))
                        {
                            EthernetInterfaceListBox.Items.Add(
                                new EthernetInterface(device.Interface.FriendlyName, device.Interface.Description));
                        }
                    }
                }
                else
                {
                    foreach (SharpPcap.LibPcap.LibPcapLiveDevice device in CaptureDeviceList.Instance)
                    {
                        EthernetInterfaceListBox.Items.Add(
                            new EthernetInterface(device.Interface.FriendlyName, device.Interface.Description));
                    }
                }
            }

            //
            // Select the one that is already selected (if any)
            //
            EthernetInterfaceListBox.SelectedIndex = 0;

            if (!string.IsNullOrEmpty(Configuration.HostPacketInterfaceName))
            {
                for (int i = 0; i < EthernetInterfaceListBox.Items.Count; i++)
                {
                    EthernetInterface iface = (EthernetInterface)EthernetInterfaceListBox.Items[i];

                    if (iface.Name == HostPacketInterfaceName)
                    {
                        EthernetInterfaceListBox.SelectedIndex = i;
                        break;
                    }
                }
            }
        }
Пример #4
0
        private void GetRouter()
        {
            //Foreach WinPcapInterface of this host
            foreach (WinPcapInterface wpc in arWpc)
            {
                if (wpc.Description == "Microsoft") //Tim added: only use my real adapter
                {
                    if (wpc.Addresses.Where(p => p.Address == new IPAddress(new byte[] { 0, 0, 0, 0 }).Address).Count() > 0) //Tim added: Only select interface that have at least one valid, non 0.0.0.0 ip address
                    {
                        //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);
                    }
                }
            }

            //Create a TCP frame
            TCPFrame tcpFrame = new TCPFrame();
            tcpFrame.DestinationPort = 80;
            tcpFrame.SourcePort = 12345;
            tcpFrame.AcknowledgementFlagSet = true;

            //Create an IP frame and put the TCP frame into it
            IPv4Frame ipFrame = new IPv4Frame();
            ipFrame.DestinationAddress = IPAddress.Parse("192.168.0.1");
            ipFrame.SourceAddress = IPAddress.Parse("192.168.1.254");

            ipFrame.EncapsulatedFrame = tcpFrame;

            rRouter.Start(); //Tim added:
                             //Send the frame
            rRouter.PushTraffic(tcpFrame);

            //Cleanup resources
            rRouter.Cleanup();

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

            //Stop all handlers
            rRouter.Stop();

            //Stop all interfaces
            foreach (EthernetInterface ipInterface in wpcInterfaces)
            {
                ipInterface.Stop();
            }
        }
Пример #5
0
 private static void TestPCap()
 {
     // Just try enumerating interfaces, if this fails for any reason we assume
     // PCap is not properly installed.
     try
     {
         List <EthernetInterface> interfaces = EthernetInterface.EnumerateDevices();
         Configuration.HostRawEthernetInterfacesAvailable = true;
     }
     catch
     {
         Configuration.HostRawEthernetInterfacesAvailable = false;
     }
 }
        /// <summary>
        /// Returns all interface extensions known by the Network Library Management Layer by default. This normally includes all Ethernet interfaces of the computer.
        /// </summary>
        /// <returns>All interface extensions known by the Network Library Management Layer by default</returns>
        public IInterfaceDefinition[] Create()
        {
            List <IInterfaceDefinition> lDefinitions = new List <IInterfaceDefinition>();

            foreach (WinPcapInterface wpc in EthernetInterface.GetAllPcapInterfaces())
            {
                if (InterfaceConfiguration.GetAdapterTypeForInterface(wpc.Name) == System.Net.NetworkInformation.NetworkInterfaceType.Ethernet ||
                    InterfaceConfiguration.GetAdapterTypeForInterface(wpc.Name) == System.Net.NetworkInformation.NetworkInterfaceType.Wireless80211)
                {
                    lDefinitions.Add(new EthernetInterfaceControlDefinition(wpc));
                }
            }

            return(lDefinitions.ToArray());
        }
Пример #7
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            try
            {
                int testValue = Convert.ToByte(AltoEthernetAddressTextBox.Text, 8);

                if (testValue < 1 || testValue > 255)
                {
                    throw new ArgumentOutOfRangeException("Invalid host address.");
                }
            }
            catch
            {
                MessageBox.Show("The Alto Ethernet address must be an octal value between 1 and 376.");
                return;
            }

            //
            // Commit changes back to Configuration.
            //

            EthernetInterface iface = (EthernetInterface)EthernetInterfaceListBox.SelectedItem;

            //
            // First warn the user of changes that require a restart.
            //
            if ((!(String.IsNullOrEmpty(Configuration.HostPacketInterfaceName) && EthernetInterfaceListBox.SelectedIndex == 0) &&
                 (Configuration.HostPacketInterfaceName != iface.Name ||
                  Configuration.HostPacketInterfaceType != _selectedInterfaceType)) ||
                Configuration.SystemType != _selectedSystemType)
            {
                MessageBox.Show("Changes to CPU or host Ethernet configuration will not take effect until ContrAlto is restarted.");
            }

            // System
            Configuration.SystemType = _selectedSystemType;

            // Ethernet
            Configuration.HostAddress             = Convert.ToByte(AltoEthernetAddressTextBox.Text, 8);
            Configuration.HostPacketInterfaceName = iface.Name;
            Configuration.HostPacketInterfaceType = _selectedInterfaceType;

            // Display
            Configuration.InterlaceDisplay = InterlaceDisplayCheckBox.Checked;
            Configuration.ThrottleSpeed    = ThrottleSpeedCheckBox.Checked;

            this.Close();
        }
Пример #8
0
        bool Repair()
        {
            LogThis(LogLevel.Debug, "-> Repair any broken setting which can be repaired ...");

            bool anyPersistedConfigRepaired = false;

            LogThis(LogLevel.Trace, $"Checking if {InterfaceType.Ethernet.GetDescriptionString()} needs any repairing ...");
            if (EthernetInterface != null && EthernetInterface.RepairConfig(InterfaceType.Ethernet) == true)
            {
                anyPersistedConfigRepaired = true;
            }

            LogThis(LogLevel.Trace, $"Checking if {InterfaceType.WiFi.GetDescriptionString()} needs any repairing ...");
            if (WifiInterface != null && WifiInterface.RepairConfig(InterfaceType.WiFi) == true)
            {
                anyPersistedConfigRepaired = true;
            }

            LogThis(LogLevel.Trace, $"Finished repair. Repairs done: {anyPersistedConfigRepaired}");
            return(anyPersistedConfigRepaired);
        }
Пример #9
0
        private void PopulateNetworkAdapterList(PacketInterfaceType encapType)
        {
            //
            // Populate the list with the interfaces available on the machine, for the
            // type of encapsulation being used.
            //
            HostInterfaceGroupBox.Enabled = encapType != PacketInterfaceType.None;

            EthernetInterfaceListBox.Items.Clear();


            // Add the "Use no interface" option
            EthernetInterfaceListBox.Items.Add(
                new EthernetInterface("None", "No network adapter"));


            switch (encapType)
            {
            // For UDP we show all interfaces that support IPV4, for Raw Ethernet we show only Ethernet interfaces.
            case PacketInterfaceType.UDPEncapsulation:
            {
                NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();

                foreach (NetworkInterface iface in interfaces)
                {
                    if (iface.Supports(NetworkInterfaceComponent.IPv4))
                    {
                        EthernetInterfaceListBox.Items.Add(new EthernetInterface(iface.Name, iface.Description));
                    }
                }
            }
            break;

            // Add all interfaces that PCAP knows about.
            case PacketInterfaceType.EthernetEncapsulation:
                if (Configuration.HostRawEthernetInterfacesAvailable)
                {
                    foreach (LivePacketDevice device in LivePacketDevice.AllLocalMachine)
                    {
                        EthernetInterfaceListBox.Items.Add(new EthernetInterface(device.GetNetworkInterface().Name, device.GetNetworkInterface().Description));
                    }
                }
                break;

            case PacketInterfaceType.None:
                // Add nothing.
                break;
            }


            //
            // Select the one that is already selected (if any)
            //
            EthernetInterfaceListBox.SelectedIndex = 0;

            if (!string.IsNullOrEmpty(Configuration.HostPacketInterfaceName))
            {
                for (int i = 0; i < EthernetInterfaceListBox.Items.Count; i++)
                {
                    EthernetInterface iface = (EthernetInterface)EthernetInterfaceListBox.Items[i];

                    if (iface.Name == Configuration.HostPacketInterfaceName)
                    {
                        EthernetInterfaceListBox.SelectedIndex = i;
                        break;
                    }
                }
            }
        }
Пример #10
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            try
            {
                int testValue = Convert.ToByte(AltoEthernetAddressTextBox.Text, 8);

                if (testValue < 1 || testValue > 255)
                {
                    throw new ArgumentOutOfRangeException("Invalid host address.");
                }
            }
            catch
            {
                MessageBox.Show("The Alto Ethernet address must be an octal value between 1 and 376.");
                return;
            }

            //
            // Commit changes back to Configuration.
            //

            EthernetInterface iface = (EthernetInterface)EthernetInterfaceListBox.SelectedItem;

            //
            // First warn the user of changes that require a restart.
            //
            if ((!(String.IsNullOrEmpty(Configuration.HostPacketInterfaceName) && EthernetInterfaceListBox.SelectedIndex == 0) &&
                 (Configuration.HostPacketInterfaceName != iface.Name ||
                  Configuration.HostPacketInterfaceType != _selectedInterfaceType)) ||
                Configuration.SystemType != _selectedSystemType)
            {
                MessageBox.Show("Changes to CPU or host Ethernet configuration will not take effect until ContrAlto is restarted.");
            }

            // System
            Configuration.SystemType = _selectedSystemType;

            // Ethernet
            Configuration.HostAddress             = Convert.ToByte(AltoEthernetAddressTextBox.Text, 8);
            Configuration.HostPacketInterfaceName = iface.Name;
            Configuration.HostPacketInterfaceType = _selectedInterfaceType;

            // Display
            Configuration.InterlaceDisplay = InterlaceDisplayCheckBox.Checked;
            Configuration.ThrottleSpeed    = ThrottleSpeedCheckBox.Checked;

            // DAC
            Configuration.EnableAudioDAC        = EnableDACCheckBox.Checked;
            Configuration.EnableAudioDACCapture = EnableDACCaptureCheckBox.Checked;
            Configuration.AudioDACCapturePath   = DACOutputCapturePathTextBox.Text;

            // Printing
            Configuration.EnablePrinting   = EnablePrintingCheckBox.Checked;
            Configuration.PrintOutputPath  = PrintOutputPathTextBox.Text;
            Configuration.ReversePageOrder = ReversePageOrderCheckBox.Checked;

            // Validate that the DAC output folder exists, if not, warn the user
            if (Configuration.EnableAudioDACCapture && !Directory.Exists(Configuration.AudioDACCapturePath))
            {
                MessageBox.Show("Warning: The specified DAC output capture path does not exist or is inaccessible.");
            }

            // Validate that the Print output folder exists, if not, warn the user
            if (Configuration.EnablePrinting && !Directory.Exists(Configuration.PrintOutputPath))
            {
                MessageBox.Show("Warning: The specified Print output path does not exist or is inaccessible.");
            }

            this.Close();
        }
 public EthernetInterfaceConfigurationWriter(TrafficHandler thToSave)
     : base(thToSave)
 {
     thHandler = (EthernetInterface)thToSave;
 }
Пример #12
0
 public EthernetInterfaceConfigurationLoader(TrafficHandler thHandler)
     : base(thHandler)
 {
     this.thHandler = (EthernetInterface)thHandler;
 }
Пример #13
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();
            }
        }
Пример #14
0
        private void PopulateNetworkAdapterList(PacketInterfaceType encapType)
        {
            //
            // Populate the list with the interfaces available on the machine, for the
            // type of encapsulation being used.
            //
            HostInterfaceGroupBox.Enabled = encapType != PacketInterfaceType.None;

            EthernetInterfaceListBox.Items.Clear();


            // Add the "Use no interface" option
            EthernetInterfaceListBox.Items.Add(
                new EthernetInterface("None", "No network adapter"));


            switch (encapType)
            {
            // For UDP we show all interfaces that support IPV4, for Raw Ethernet we show only Ethernet interfaces.
            case PacketInterfaceType.UDPEncapsulation:
            {
                NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();

                foreach (NetworkInterface iface in interfaces)
                {
                    if (iface.Supports(NetworkInterfaceComponent.IPv4))
                    {
                        EthernetInterfaceListBox.Items.Add(new EthernetInterface(iface.Name, iface.Description));
                    }
                }
            }
            break;

            // Add all interfaces that PCAP knows about.
            case PacketInterfaceType.EthernetEncapsulation:
                if (Configuration.HostRawEthernetInterfacesAvailable)
                {
                    foreach (WinPcapDevice device in CaptureDeviceList.Instance)
                    {
                        //
                        // NCap seems to return some interfaces with a null FriendlyName; empirically these
                        // are not real network adapters that would typically be used with ContrAlto so we
                        // will not display them here.
                        //
                        if (!string.IsNullOrWhiteSpace(device.Interface.FriendlyName))
                        {
                            EthernetInterfaceListBox.Items.Add(new EthernetInterface(device.Interface.FriendlyName, device.Interface.Description));
                        }
                    }
                }
                break;

            case PacketInterfaceType.None:
                // Add nothing.
                break;
            }

            //
            // Select the one that is already selected (if any)
            //
            EthernetInterfaceListBox.SelectedIndex = 0;

            if (!string.IsNullOrEmpty(Configuration.HostPacketInterfaceName))
            {
                for (int i = 0; i < EthernetInterfaceListBox.Items.Count; i++)
                {
                    EthernetInterface iface = (EthernetInterface)EthernetInterfaceListBox.Items[i];

                    if (iface.Name == Configuration.HostPacketInterfaceName)
                    {
                        EthernetInterfaceListBox.SelectedIndex = i;
                        break;
                    }
                }
            }
        }
Пример #15
0
 private void Box_list_SelectedIndexChanged(object sender, EventArgs e)
 {
     SelectedInterface = box_list.SelectedItem as EthernetInterface;
 }
Пример #16
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();
            }
        }