Exemplo n.º 1
0
 public void NpcapDeviceListNullAuthTest()
 {
     using (new RemotePcapServer(NullAuthArgs))
     {
         var auth = new RemoteAuthentication(AuthenticationTypes.Null, null, null);
         CollectionAssert.IsNotEmpty(NpcapDeviceList.Devices(IPAddress.Loopback, 2002, auth));
         CollectionAssert.IsNotEmpty(NpcapDeviceList.Devices(IPAddress.Loopback, 2002, null));
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)

        {
            args = new string[] { "192.169.127.4" };
            if ((args.Length < 1) || (args.Length > 2))
            {
                PrintUsage("NpcapRemoteCapture");
                return;
            }
            // 通过运行'rpcapd.exe文件'在远程服务器上。默认情况下,服务器使用端口2003
            // 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 = NpcapDeviceList.Devices(ipAddress, port, null);

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

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

            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.º 3
0
        public void PwdAuthTest()
        {
            try
            {
                if (!TestUser.Create())
                {
                    Assert.Inconclusive("Please rerun the test as administrator.");
                }
                var goodCred = new RemoteAuthentication(AuthenticationTypes.Password, TestUser.Username, TestUser.Password);
                var badCred  = new RemoteAuthentication(AuthenticationTypes.Password, "foo", "bar");
                using (new RemotePcapServer(PwdAuthArgs))
                {
                    var pcapIfs      = PcapInterface.GetAllPcapInterfaces("rpcap://localhost/", goodCred);
                    var npcapDevices = NpcapDeviceList.Devices(IPAddress.Loopback, NpcapDeviceList.RpcapdDefaultPort, goodCred);
                    CollectionAssert.IsNotEmpty(npcapDevices);

                    var devices = new PcapDevice[] {
                        // using NpcapDevice
                        npcapDevices[0],
                        // using rpcap with LibPcapLiveDevice should be possible
                        new LibPcapLiveDevice(pcapIfs[0])
                    };
                    foreach (var device in devices)
                    {
                        // repassing the auth to Open() should be optional
                        device.Open();
                        Assert.IsTrue(device.Opened);
                        device.Close();
                    }

                    Assert.Throws <PcapException>(
                        () => npcapDevices[0].Open(OpenFlags.NoCaptureRemote, 1, badCred),
                        "Credentials provided to Open() method takes precedence"
                        );

                    Assert.Throws <PcapException>(
                        () => PcapInterface.GetAllPcapInterfaces("rpcap://localhost/", badCred)
                        );
                }
            }
            finally
            {
                TestUser.Delete();
            }
        }
Exemplo n.º 4
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 Exception("unable to start process");
            }

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

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

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

            System.Threading.Thread.Sleep(2000);

            p.Kill();
        }