Beispiel #1
0
        /// <summary>
        /// Finds MAC address of the gateway, when its IP address is in ipOfgateway.
        /// The MAC address is stored in macOfGateway.
        /// </summary>
        /// <returns>
        ///     <c>true</c> if MAC address is found, otherwise <c>false</c>.
        /// </returns>
        protected bool findMACofGateway()
        {
            ARP arp;

            if (ipOfGateway == null)
            {
                return(false);
            }
            //get list of all available interfaces
            SharpPcap.LibPcap.LibPcapLiveDeviceList lldl = SharpPcap.LibPcap.LibPcapLiveDeviceList.Instance;
            //find MAC address of gateway
            foreach (SharpPcap.LibPcap.LibPcapLiveDevice lld in lldl)
            {
                arp = new ARP(lld);
                try
                {
                    macOfGateway = arp.Resolve(ipOfGateway);
                    Console.WriteLine("MAC of gateway: " + macOfGateway.ToString());
                    liveInterface = lld;
                }
                catch (NullReferenceException)
                {
                    continue;
                }
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public xbs_sniffer(ICaptureDevice dev, bool use_special_mac_filter, List <PhysicalAddress> filter_special_macs, bool only_forward_special_macs, xbs_node_list node_list, xbs_nat NAT, GatewayIPAddressInformationCollection gateways, bool exclude_gateway_ips)
        {
            this.NAT = NAT;
            this.pdev_filter_use_special_macs = use_special_mac_filter;
            if (filter_special_macs != null)
            {
                this.pdev_filter_special_macs = filter_special_macs;
            }
            this.pdev_filter_only_forward_special_macs = only_forward_special_macs;
            this.pdev_filter_exclude_gatway_ips        = exclude_gateway_ips;
            create_gateway_filter(gateways);
            injected_macs_hash.Capacity = 40;
            sniffed_macs_hash.Capacity  = 10;
            sniffed_macs.Capacity       = 10;

            this.node_list = node_list;

            if (!(dev is SharpPcap.LibPcap.LibPcapLiveDevice))
            {
                throw new ArgumentException("pcap caputure device is not a LibPcapLiveDevice");
            }
            this.pdev             = (SharpPcap.LibPcap.LibPcapLiveDevice)dev;
            pdev.OnPacketArrival +=
                new PacketArrivalEventHandler(OnPacketArrival);
            pdev.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            setPdevFilter();

            if (System.Environment.OSVersion.Platform == PlatformID.Win32NT && pdev is SharpPcap.WinPcap.WinPcapDevice)
            {
                ((SharpPcap.WinPcap.WinPcapDevice)pdev).MinToCopy = 10;
            }

            xbs_messages.addInfoMessage(" - sniffer created on device " + pdev.Description, xbs_message_sender.SNIFFER);

            dispatcher_thread = new Thread(new ThreadStart(dispatcher));
            dispatcher_thread.IsBackground = true;
            dispatcher_thread.Priority     = ThreadPriority.AboveNormal;
            dispatcher_thread.Start();
        }
Beispiel #3
0
        public xbs_sniffer(ICaptureDevice dev, bool use_special_mac_filter, List<PhysicalAddress> filter_special_macs, bool only_forward_special_macs, xbs_node_list node_list, xbs_nat NAT, GatewayIPAddressInformationCollection gateways, bool exclude_gateway_ips)
        {
            this.NAT = NAT;
            this.pdev_filter_use_special_macs = use_special_mac_filter;
            if (filter_special_macs!=null)
                this.pdev_filter_special_macs = filter_special_macs;
            this.pdev_filter_only_forward_special_macs = only_forward_special_macs;
            this.pdev_filter_exclude_gatway_ips = exclude_gateway_ips;
            create_gateway_filter(gateways);
            injected_macs_hash.Capacity = 40;
            sniffed_macs_hash.Capacity = 10;
            sniffed_macs.Capacity = 10;

            this.node_list = node_list;

            if (!(dev is SharpPcap.LibPcap.LibPcapLiveDevice))
                throw new ArgumentException("pcap caputure device is not a LibPcapLiveDevice");
            this.pdev = (SharpPcap.LibPcap.LibPcapLiveDevice)dev;
            pdev.OnPacketArrival +=
                new PacketArrivalEventHandler(OnPacketArrival);
            pdev.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            setPdevFilter();

            if (System.Environment.OSVersion.Platform == PlatformID.Win32NT && pdev is SharpPcap.WinPcap.WinPcapDevice)
                ((SharpPcap.WinPcap.WinPcapDevice)pdev).MinToCopy = 10;

            xbs_messages.addInfoMessage(" - sniffer created on device " + pdev.Description, xbs_message_sender.SNIFFER);

            dispatcher_thread = new Thread(new ThreadStart(dispatcher));
            dispatcher_thread.IsBackground = true;
            dispatcher_thread.Priority = ThreadPriority.AboveNormal;
            dispatcher_thread.Start();
        }