private LibPcapLiveDevice Open()
{
var devices = LibPcapLiveDeviceList.Instance.Where(dev => dev.Interface != null);
if ((deviceName != null) && (deviceName != "")) // specified interface
{
try
{
var device = devices.Where(dev => dev.Interface.FriendlyName == deviceName).FirstOrDefault();
device.Open(DeviceMode.Normal, 1000); // 1000 ms read timeout
return device;
}
catch
{
return null;
}
}
else // no interface specified, open the first Ethernet link layer (included Wifi).
{
foreach (var device in devices)
{
device.Open(DeviceMode.Normal, 1000); // 1000 ms read timeout
if (device.LinkType == PacketDotNet.LinkLayers.Ethernet
&& device.Interface.MacAddress != null)
return device;
device.Close();
}
return null;
}
}