1

我正在查看SharpPcap 教程,并试图了解如何访问设备详细信息,这来自这篇文章:在 SharpPcap 如何找到设备的 IP 地址?表示我必须将ICaptureDevice对象转换为特定类型,例如WinPcapDevice.

他们展示了如何遍历设备列表,但没有展示如何进行类型转换:

// Retrieve all capture devices
var devices = CaptureDeviceList.Instance;

// differentiate based upon types
foreach (ICaptureDevice dev in devices)
{
  if (dev is AirPcapDevice)
  {
    // process as an AirPcapDevice
  }
  else if(dev is WinPcapDevice)
  {
    // process as an WinPcapDevice
  }
  else if(dev is LibPcapLiveDevice)
  {
    // process as an LibPcapLiveDevice
  }
}
4

0 回答 0