Beispiel #1
0
        static void Main()
        {
            foreach (var filter in USBPcapClient.find_usbpcap_filters())
            {
                Console.WriteLine(filter);
                Console.WriteLine(USBPcapClient.enumerate_print_usbpcap_interactive(filter));
            }

            Console.Write("Enter filter id: ");
            if (!int.TryParse(Console.ReadLine(), out var filterId))
            {
                Console.WriteLine("Incorrect filter id!!!");
                return;
            }

            Console.Write("Enter device id: ");
            if (!int.TryParse(Console.ReadLine(), out var deviceId))
            {
                Console.WriteLine("Incorrect device id!!!");
                return;
            }

            var usbClient = new USBPcapClient($@"\\.\USBPcap{filterId}", deviceId);

            usbClient.DataRead += OnDataRead;
            usbClient.start_capture();
            while (true)
            {
                Thread.Sleep(1);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            List <string> filters = USBPcapClient.find_usbpcap_filters();

            if (filters.Count == 0)
            {
                Console.WriteLine("No filter control devices are available.");

                if (USBPcapClient.is_usbpcap_upper_filter_installed() == true)
                {
                    Console.WriteLine("Please reinstall USBPcapDriver.");
                }

                Console.WriteLine($@"USBPcap UpperFilter entry appears to be present.
Most likely you have not restarted your computer after installation.
It is possible to restart all USB devices to get USBPcap working without reboot.
{Environment.NewLine}WARNING:{Environment.NewLine}  Restarting all USB devices can result in data loss.
  If you are unsure please answer 'n' and reboot in order to use USBPcap.");

                return;
            }

            // how can I precisely specify a USB device to capture with tshark?
            // https://osqa-ask.wireshark.org/questions/53919/how-can-i-precisely-specify-a-usb-device-to-capture-with-tshark

            // Tracking only one USB Port in Filter using USBPcap
            // https://osqa-ask.wireshark.org/questions/63837/tracking-only-one-usb-port-in-filter-using-usbpcap
            int targetDeviceId = 0;
            int filterDeviceId = 1;

            if (args.Length >= 1)
            {
                targetDeviceId = int.Parse(args[0]);
            }

            if (args.Length >= 2)
            {
                filterDeviceId = int.Parse(args[1]);
            }

            Console.WriteLine("Following filter control devices are available:");
            string target = null;

            int i = 0;

            foreach (string filter in filters)
            {
                Console.WriteLine($"{i + 1} {filter}");

                string deviceList = USBPcapClient.enumerate_print_usbpcap_interactive(filter);
                Console.WriteLine(deviceList);

                if (targetDeviceId == i)
                {
                    target = filter;
                    break;
                }

                i++;
            }

            if (string.IsNullOrEmpty(target) == false)
            {
                using (USBPcapClient usbCapture = new USBPcapClient(target, filterDeviceId))
                {
                    usbCapture.HeaderRead += UsbCapture_HeaderRead;
                    usbCapture.DataRead   += UsbCapture_DataRead;

                    usbCapture.start_capture();

                    usbCapture.wait_for_exit_signal();
                }
            }
        }