Ejemplo n.º 1
0
        /// <summary>
        /// Populate the available network cards
        /// </summary>
        public List <string> PopulateInterfaces()//Not used
        {
            CaptureDeviceList capturedevicelist         = CaptureDeviceList.Instance;
            List <string>     capturedevicelistofstring = new List <string>();

            capturedevicelist.ToList().ForEach((ICaptureDevice capturedevice) =>
            {
                if (capturedevice is WinPcapDevice)
                {
                    WinPcapDevice winpcapdevice = (WinPcapDevice)capturedevice;
                    capturedevicelistofstring.Add(winpcapdevice.Interface.FriendlyName);
                }
                else if (capturedevice is AirPcapDevice)
                {
                    AirPcapDevice airpcapdevice = (AirPcapDevice)capturedevice;
                    capturedevicelistofstring.Add(airpcapdevice.Interface.FriendlyName);
                }
            });
            return(capturedevicelistofstring);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Populate the available network cards
        /// </summary>
        public void PopulateInterfaces()
        {
            CaptureDeviceList capturedevicelist         = CaptureDeviceList.Instance;
            List <string>     capturedevicelistofstring = new List <string>();

            capturedevicelist.ToList().ForEach((ICaptureDevice capturedevice) =>
            {
                if (capturedevice is WinPcapDevice)
                {
                    WinPcapDevice winpcapdevice = (WinPcapDevice)capturedevice;
                    capturedevicelistofstring.Add(winpcapdevice.Interface.FriendlyName);
                }
                else if (capturedevice is AirPcapDevice)
                {
                    AirPcapDevice airpcapdevice = (AirPcapDevice)capturedevice;
                    capturedevicelistofstring.Add(airpcapdevice.Interface.FriendlyName);
                }
            });
            _view.ToolStripComboBoxDeviceList.Items.AddRange(capturedevicelistofstring.ToArray());
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            string ver = SharpPcap.Version.VersionString;

            Console.WriteLine("SharpPcap {0}", ver);


            CaptureDeviceList devices = CaptureDeviceList.Instance;

            if (devices.Count < 1)
            {
                Console.WriteLine("No devices found.");
            }

            Console.WriteLine("Devices found:");
            devices.ToList().ForEach(Console.WriteLine);


            ICaptureDevice localAreaNetworkNIC = devices[1];

            localAreaNetworkNIC.OnPacketArrival += new PacketArrivalEventHandler(localAreaNetworkNIC_OnPacketArrival);

            // open device
            int readTimeoutMill = 1000;

            localAreaNetworkNIC.Open(DeviceMode.Promiscuous, readTimeoutMill);

            localAreaNetworkNIC.Filter = "ip and tcp";

            Console.WriteLine("Filtering: {0}", localAreaNetworkNIC.Filter);
            Console.WriteLine("Listening on {0}", localAreaNetworkNIC.Description);

            localAreaNetworkNIC.StartCapture();

            Console.ReadLine();

            localAreaNetworkNIC.StopCapture();

            localAreaNetworkNIC.Close();
        }