Beispiel #1
0
        static void Main()
        {
            var api = WinpkFilterDriver.Open();

            if (api.Handle.IsInvalid)
            {
                throw new ApplicationException("Cannot load driver.");
            }
            foreach (var device in api.GetNetworkDevices())
            {
                PassThruThread(device);
            }
            Console.ReadLine();
        }
        public void TestFirewall(FirewallCheck check)
        {
            var index = IpHelper.GetBestInterfaceIndex(WebHelper.Address);
            var name  = NetworkInterface.GetAllNetworkInterfaces()
                        .First(nic => nic.GetIPProperties().GetIPv4Properties().Index == index)
                        .Name;

            using var driver = WinpkFilterDriver.Open();
            using var device = driver.GetNetworkDevices().First(d => d.FriendlyName == name);
            Assert.IsFalse(device.Started);
            device.OnPacketArrival += check.OnPacketArrival;

            device.Open(DeviceModes.Promiscuous);
            device.AdapterMode = AdapterModes.Tunnel;
            device.StartCapture();
            // Wait for the capture thread to start
            Thread.Sleep(1000);
            Assert.IsTrue(device.Started);
            var status = WebHelper.WebFetch();

            Assert.AreEqual(check.ExpectedStatus, status);
        }
        public void Properties()
        {
            using var driver = WinpkFilterDriver.Open();

            Assert.NotZero(driver.Version);

            foreach (var device in driver.GetNetworkDevices())
            {
                Assert.IsNotNull(device.Name);
                Assert.IsNotNull(device.FriendlyName);
                Assert.IsNull(device.Description);
                Assert.IsNull(device.LastError);
                Assert.IsNull(device.Filter);
                Assert.AreEqual(LinkLayers.Ethernet, device.LinkType);
                Assert.IsNotNull(device.MacAddress);
                Assert.AreEqual(TimestampResolution.Microsecond, device.TimestampResolution);
                Assert.IsNull(device.Statistics);
                if (device.IsValid)
                {
                    // unless explicitly changed by user, this is the default for Ethernet adapters
                    Assert.AreEqual(1500, device.Mtu);
                }
            }
        }