コード例 #1
0
ファイル: Program.cs プロジェクト: harisali45/anti-snooper
        /// <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);
        }
コード例 #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();
        }
コード例 #3
0
ファイル: xbs_sniffer.cs プロジェクト: Ch0wW/XBSlink
        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();
        }