Search code examples
c#sharppcap

List devices by IPs?


How could I list the devices by IP instead of name ?

I am aware that I can get the device name and description but since I have many devices installed it would be rather easier if I could get it by IP to select one, but I couldnt find any option related so I am wondering if there is an approach to it ?

foreach (var dev in CaptureDeviceList.Instance)
{
    var str = String.Format("{0} {1}", dev.Name, dev.Description);
    iDeviceDropDown.Items.Add(str);
}

Solution

  • UPDATE, Found a solution:

    private void GetDevices()
    {
        foreach (SharpPcap.LibPcap.LibPcapLiveDevice dev in SharpPcap.LibPcap.LibPcapLiveDeviceList.Instance)
        {
            for (int i = 0; i < dev.Addresses.Count; i++)
            {
                var ip = dev.Addresses[i].Addr.ipAddress;
                if (ip == null)
                    continue;
    
                iDeviceDropDown.Items.Add(ip.ToString());
            }
        }
    }