CSharp Pcap的网络唤醒
var devices = CaptureDeviceList.Instance;
// if no devices were found print an error
if(devices.Count < 1)
{
Console.WriteLine("No devices were found on this machine");
return;
}
Console.WriteLine("The following devices are available on this machine:");
Console.WriteLine("----------------------------------------------------");
Console.WriteLine();
int i = 0;
// scan the list printing every entry
foreach(var dev in devices)
{
Console.WriteLine("{0}) {1} {2}",i,dev.Name,dev.Description);
i ;
}
Console.WriteLine();
Console.Write("-- Please choose a device to capture: ");
i = int.Parse(Console.ReadLine());
var device1 = devices[i];
var device2 = CaptureDeviceList.New()[i];
// register our handler function to the 'packet arrival' event
device1.OnPacketArrival =
new PacketArrivalEventHandler(device_OnPacketArrival);
device2.OnPacketArrival =
new PacketArrivalEventHandler(device_OnPacketArrival);
// open the device for capturing
int readTimeoutMilliseconds = 1000;
device1.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
device2.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
// tcpdump filter to capture only TCP/IP packets
device1.Filter = "ether dst FF:FF:FF:FF:FF:FF and udp";
device2.Filter = "ether dst FF:FF:FF:FF:FF:FF and ether proto 0x0842";
Console.WriteLine();
Console.WriteLine("-- Listening for packets... Hit 'Ctrl-C' to exit --");
// start capture packets
device1.Capture();
device2.Capture();
评论