Esempio n. 1
0
 //checks device/interface to see if there is traffic on it, same logic as Sniffer
 private static void IsDeviceActive(NpcapDevice device)
 {
     device.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(DeviceConnectivityHandler);
     device.Open(DeviceMode.Promiscuous, 1000);
     device.Filter = "ip and tcp";
     device.StartCapture();
     Thread.Sleep(1000);
     device.StopCapture();
     device.Close();
 }
Esempio n. 2
0
 public void start(int deviceId)
 {
     if (!_statsOn)
     {
         init(deviceId);
         Console.WriteLine();
         Console.WriteLine("-- Gathering statistics on \"{0}\", hit 'Enter' to stop...",
                           _device.Description);
         // Start the capturing process
         _device.StartCapture();
         _statsOn = true;
     }
 }
Esempio n. 3
0
        /*
         * get list of all device interfaces on machine, iterate through list and check for wifi/ethernet connectivity
         * collect packets for 00:01:30, print to console.
         */
        private static void Sniffer()
        {
            NpcapDeviceList devices      = NpcapDeviceList.Instance;
            NpcapDevice     activeDevice = null;

            foreach (NpcapDevice currentDevice in devices)
            {
                IsDeviceActive(currentDevice);
                if ((isDeviceActive && ((currentDevice.ToString().Contains("FriendlyName: Wi-Fi")) || (currentDevice.ToString().Contains("FriendlyName: Ethernet")))))
                {
                    activeDevice = currentDevice;
                    break;
                }
            }
            foreach (PcapAddress ipaddress in activeDevice.Addresses)
            {
                if (ipaddress.Addr != null && ipaddress.Addr.ipAddress != null)
                {
                    if (ipaddress.Addr.ipAddress.ToString().Contains("192.168"))
                    {
                        currentDeviceLocalIp = ipaddress.Addr.ipAddress;
                        break;
                    }
                }
            }

            activeDevice.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(PacketHandler);
            Console.WriteLine(string.Format("{0}\n", activeDevice));
            Console.WriteLine("Initiating Packet Capture...");
            activeDevice.Open(DeviceMode.Promiscuous, 1000);
            activeDevice.Filter = "ip and tcp";
            activeDevice.StartCapture();
            Thread.Sleep(90000);
            activeDevice.StopCapture();
            activeDevice.Close();
            Console.WriteLine("...Packet Capture complete.");
            Console.WriteLine("==============================================\n\n\n");
        }