Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of this class
        /// </summary>
        public NetMap()
        {
            ndiuUtility = new NetDiscoveryUtility();
            ndiuUtility.OnResolveFinished += new NetDiscoveryUtility.ResolveCompletedEventHandler(ndiuUtility_OnResolveFinished);
            lHosts                = new List <Host>();
            dictIPHost            = new Dictionary <IPAddress, Host>();
            dictMACHost           = new Dictionary <MACAddress, Host>();
            lDataLinkNeighbours   = new List <Host>();
            lUpperLayerNeighbours = new List <Host>();
            lDataLinkDistributors = new List <Host>();
            ResolveHostnames      = true;

            hLocalhost = CreateHost(System.Environment.MachineName);
            Host hNetwork;

            IPAddress[]  ipa;
            Subnetmask[] smMasks;
            MACAddress   mcMac;

            string[] strInterfaces = InterfaceConfiguration.GetAllInterfaceNames();

            for (int iC2 = 0; iC2 < strInterfaces.Length; iC2++)
            {
                if (strInterfaces[iC2] != null)
                {
                    ipa     = InterfaceConfiguration.GetIPAddressesForInterface(strInterfaces[iC2]);
                    smMasks = InterfaceConfiguration.GetIPSubnetsForInterface(strInterfaces[iC2]);
                    mcMac   = InterfaceConfiguration.GetMacAddressForInterface(strInterfaces[iC2]);
                    if (ipa != null)
                    {
                        for (int iC1 = 0; iC1 < ipa.Length; iC1++)
                        {
                            if (ipa[iC1].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                            {
                                if (smMasks != null && smMasks.Length > iC1)
                                {
                                    AddIPToHost(hLocalhost, ipa[iC1]);
                                    hNetwork = CreateHost("Network");
                                    SetAsDistributionDevice(hNetwork);
                                    hNetwork.Properties.Add("subnetmask", smMasks[iC1]);
                                    hNetwork.Properties.Add("network", IPAddressAnalysis.GetClasslessNetworkAddress(ipa[iC1], smMasks[iC1]));
                                    AddIPToHost(hNetwork, IPAddressAnalysis.GetClasslessNetworkAddress(ipa[iC1], smMasks[iC1]));
                                    lDataLinkDistributors.Add(hNetwork);
                                    Connect(hNetwork, hLocalhost);
                                }
                            }
                        }
                    }
                    if (mcMac != null)
                    {
                        AddMACToHost(hLocalhost, mcMac);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public TCPStreamModifier()
        {
            lStacks = new List <TCPStreamModifierStack>();
            AutoExcludeLocalConnections = true;
            lLocalAddresses             = new List <IPAddress>();

            foreach (string strInterface in InterfaceConfiguration.GetAllInterfaceNames())
            {
                lLocalAddresses.AddRange(InterfaceConfiguration.GetIPAddressesForInterface(strInterface));
            }
        }
        /// <summary>
        /// Creates a new instance of this class, listening to the given interface
        /// </summary>
        /// <param name="wpcInterface">A WinPcapInterface which defines the interface to listen to</param>
        public EthernetInterface(WinPcapInterface wpcInterface)
        {
            if (InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.Ethernet &&
                InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.Ethernet3Megabit &&
                InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.FastEthernetFx &&
                InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.FastEthernetT &&
                InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.GigabitEthernet &&
                InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.Wireless80211)
            {
                throw new ArgumentException("Only enabled ethernet interfaces are supported at the moment.");
            }
            if (wpcInterface.Name == null)
            {
                throw new ArgumentException("Cannot create an interface instance for an interface not properly recognised by WinPcap.");
            }

            bPromiscousMode          = true;
            oInterfaceStartStopLock  = new object();
            AddressResolutionMethod  = AddressResolution.NDP;
            bExcludeOwnTraffic       = true;
            bExcludeLocalHostTraffic = true;
            arpHostTable             = new HostTable();
            lmacSpoofAdresses        = new List <MACAddress>();
            bRun             = false;
            bShutdownPending = false;

            qFrameQueue       = new Queue <byte[]>();
            bIsRunning        = false;
            areWorkToDo       = new AutoResetEvent(false);
            this.wpcInterface = wpcInterface;
            wpcDevice         = new WinPcapDotNet();

            this.maMacAddress = InterfaceConfiguration.GetMacAddressForInterface(wpcInterface.Name);
            this.aType        = InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name);
            this.MTU          = InterfaceConfiguration.GetMtuForInterface(wpcInterface.Name) - 18; //Reserve 18 bytes for our ethernet-header

            IPAddress[]  arip   = InterfaceConfiguration.GetIPAddressesForInterface(wpcInterface.Name);
            Subnetmask[] smMask = InterfaceConfiguration.GetIPSubnetsForInterface(wpcInterface.Name);

            for (int iC1 = 0; iC1 < arip.Length && iC1 < smMask.Length; iC1++)
            {
                this.AddAddress(arip[iC1], smMask[iC1]);
            }

            ipStandardgateways.AddRange(InterfaceConfiguration.GetIPStandardGatewaysForInterface(wpcInterface.Name));
            this.strDNSName   = Dns.GetHostName();
            PrimaryMACAddress = this.MACAddress;
        }