0

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);
}
Prix
  • 19,417
  • 15
  • 73
  • 132

2 Answers2

1

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());
        }
    }
}
Prix
  • 19,417
  • 15
  • 73
  • 132
0

I see there is a ICaptureDevice.MacAddress property of type System.Net.NetworkInformation.PhysicalAddress. I don't think there is a direct way to get IP address from MAC Address but you can look it up using NetworkInterface.GetAllNetworkInterfaces();

Bala R
  • 107,317
  • 23
  • 199
  • 210