Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if ((args.Length < 1) || (args.Length > 2))
            {
                PrintUsage("WinPcapRemoteCapture");
                return;
            }

            // ensure that a remote capture daemon has been started by running
            // 'rpcapd.exe' on the remote server. By default port 2003 is used for the server

            var ipAddress = System.Net.IPAddress.Parse(args[0]);
            var port      = rpcapDefaultPort;

            if (args.Length == 2)
            {
                port = Int32.Parse(args[1]);
            }

            var remoteDevices = WinPcapDeviceList.Devices(ipAddress, port, null);

            foreach (var dev in remoteDevices)
            {
                Console.WriteLine("device: {0}", dev.ToString());
            }

            // open the device for capture
            var device = remoteDevices[0];

            device.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(dev_OnPacketArrival);

            device.Open(0, 500, null);

            Console.WriteLine();
            Console.WriteLine("-- Listening on {0}, hit 'Enter' to stop...",
                              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();
        }
Exemplo n.º 2
0
        public void RemoteTest()
        {
            var     noAuthenticationParameter = "-n";
            var     exe1 = "c:\\Program Files (x86)\\WinPcap\\rpcapd.exe";
            var     exe2 = "c:\\Program Files\\WinPcap\\rpcapd.exe";
            Process p;

            try
            {
                p = System.Diagnostics.Process.Start(exe1, noAuthenticationParameter);
            } catch (Exception)
            {
                try
                {
                    p = System.Diagnostics.Process.Start(exe2, noAuthenticationParameter);
                } catch (Exception)
                {
                    throw;
                }
            }

            if (p == null)
            {
                throw new System.Exception("unable to start process");
            }

            // wait until the process has started up
            System.Threading.Thread.Sleep(500);

            // retrieve the device list
            var defaultPort = WinPcapDeviceList.RpcapdDefaultPort;
            var deviceList  = WinPcapDeviceList.Devices(System.Net.IPAddress.Loopback, defaultPort, null);

            foreach (var d in deviceList)
            {
                Console.WriteLine(d.ToString());
            }

            System.Threading.Thread.Sleep(2000);

            p.Kill();
        }