public string[] ProvideDeviceNames() { // Print SharpPcap version string ver = SharpPcap.Version.VersionString; Console.WriteLine("SharpPcap {0}, Example1.IfList.cs", ver); // Retrieve the device list LivePcapDeviceList devices = LivePcapDeviceList.Instance; LivePcapDevice device = null; // If no devices were found print an error if (devices.Count < 1) { //Console.WriteLine("No devices were found on this machine"); return(null); } devc = new string[150]; // Print out the available network devices int i = 0; foreach (LivePcapDevice dev in devices) { devc[i] = dev.Description; i += 1; /////////////////////Console.WriteLine("{0}\n", dev.ToString()); } return(devc); }
void PopulateInterfaceCombobox() { LivePcapDeviceList deviceList = LivePcapDeviceList.Instance; if (deviceList.Count > 0) { foreach (LivePcapDevice device in deviceList) { PcapAddress address = GetIPV4Sockddr(device); cbInterface.Items.Add(String.Format("{0} -- {1}", device.Interface.FriendlyName, address.Addr.ipAddress)); } } }
private void GetNICList() { LivePcapDeviceList devices = null; try { devices = LivePcapDeviceList.Instance; /* Scan the list printing every entry */ foreach (LivePcapDevice dev in devices) { cmbNIC.Items.Add(dev.Description.ToString()); } } catch (Exception) { UpdateStatus("Error loading network card list"); } }
private void LogDeviceList() { LivePcapDeviceList deviceList = LivePcapDeviceList.Instance; if (deviceList.Count < 1) { Log("No devices were found on this machine"); } else { Log(String.Format("The following devices are available on this machine:{0}", Environment.NewLine)); foreach (LivePcapDevice device in deviceList) { Log(device.Interface.FriendlyName); Log(String.Format("{0}: {1}", device.Description, device.Interface.Name)); PcapAddress address = GetIPV4Sockddr(device); Log(address.ToString()); } } }
private void StartFilter() { m_Device = null; while (!m_bStop) { try { LivePcapDeviceList devices = null; devices = LivePcapDeviceList.Instance; int i = 0; /* Scan the list printing every entry */ foreach (LivePcapDevice dev in devices) { if (dev.Description.ToString() == m_strNIC) { m_Device = devices[i]; break; } else { i++; } } if (m_Device == null) { m_IStatusUpdate.UpdateStatus("Failed to get handle to NIC"); } else { //Open the device for capturing int readTimeoutMilliseconds = 1000; m_Device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds); //Register our handler function to the 'packet arrival' event m_Device.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival); // udpdump filter to capture only UDP/IP packets string filter = "udp"; m_Device.SetFilter(filter); if (m_dtBound != DateTime.MaxValue) { m_IStatusUpdate.UpdateStatus("Next update at " + (m_dtBound + m_spanLease).ToString()); } else { m_IStatusUpdate.UpdateStatus("Started DHCP Client..."); } // Start capture packets m_Device.Capture(); // NO stop request... if (!m_bStop) { if (m_Device != null) { m_Device.Close(); m_Device = null; } } } } catch (Exception exc) { m_IStatusUpdate.UpdateStatus("Exception: " + exc.Message); try { m_Device.Close(); } catch (Exception) { } m_Device = null; } Thread.Sleep(1000); } }