Уровень сигнала от запроса зонда - Sharppcap - PullRequest
0 голосов
/ 20 апреля 2020

Я пытаюсь получить уровень сигнала пробного запроса, используя sharppcap в c#.

В настоящее время, насколько я вижу, мне нужно получить данные из PpiCommon, но я не знаю как туда добраться. Я попытался извлечь PpiPacket, как показано в моем коде ниже, но безрезультатно, поскольку он просто нулевой. Код является просто измененным примером.

Заранее спасибо:)

using System;
using System.Linq;
using SharpPcap;
using SharpPcap.LibPcap;
using System.Net.NetworkInformation;
using PacketDotNet;
using PacketDotNet.Ieee80211;

namespace MqttPublisher
{
    class Program
    {
        static void Main(string[] args)
        {
            // Print SharpPcap version
            string ver = SharpPcap.Version.VersionString;
            Console.WriteLine("SharpPcap version: {0}", ver);

            // Retrieve the device list
            CaptureDeviceList 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();
            Console.WriteLine("The following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine();

            int i = 0;

            // Print out the devices
            foreach (ICaptureDevice dev in devices)
            {
                /* Description */
                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());

            ICaptureDevice device = devices[i];

            // Register our handler function to the 'packet arrival' event
            device.OnPacketArrival +=
                new PacketArrivalEventHandler(device_OnPacketArrival);

            // Open the device for capturing
            int readTimeoutMilliseconds = 1000;
            LibPcapLiveDevice livePcapDevice = device as LibPcapLiveDevice;
            livePcapDevice.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);

            string filter = "wlan type mgt subtype probe-req";
            livePcapDevice.Filter = filter;

            Console.WriteLine();
            Console.WriteLine("Listening on {0} {1}, hit 'Enter' to stop", device.Name, device.Description);

            // Start the capturing process
            device.StartCapture();

            // Wait for 'Enter' from the user.
            Console.ReadLine();

            // Stop the capturing process
            device.StopCapture();

            Console.WriteLine("-- Capture stopped.");

            // Print out the device statistics
            Console.WriteLine(device.Statistics.ToString());

            // Close the pcap device
            device.Close();
        }

        private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
        {
            var time = e.Packet.Timeval.Date;
            var len = e.Packet.Data.Length;

            var packet = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
            var pack = packet.Extract<PacketDotNet.Ieee80211.ProbeRequestFrame>();
            PpiPacket test = packet.Extract<PacketDotNet.Ieee80211.PpiPacket>();

            if (test != null)
            {
                Console.WriteLine("Packet is not null");
            }
            if (pack != null)
            {
                PhysicalAddress src = pack.SourceAddress;
                PhysicalAddress dst = pack.DestinationAddress;

                PhysicalAddress ssid = pack.BssId;

                Console.WriteLine("{0} -> {1}, {2}", src, dst, ssid);
            }
            else
            {
                Console.WriteLine("Packet could not be extracted\n");
            }
        }
    }
}

...