public void TestSend() { var dst = IPAddress.Parse("8.8.8.8"); var nic = IpHelper.GetBestInterface(dst); Assert.NotNull(nic, "No internet connected interface found"); var src = nic.GetIPProperties().UnicastAddresses .Select(addr => addr.Address) .FirstOrDefault(addr => addr.AddressFamily == AddressFamily.InterNetwork); var ifIndex = nic.GetIPProperties().GetIPv4Properties().Index; Console.WriteLine($"Using NIC {nic.Name} [{ifIndex}]"); Console.WriteLine($"Sending from {src} to {dst}"); var device = new WinDivertDevice(); device.Open(); try { var udp = new UdpPacket(5000, 5000); udp.PayloadData = new byte[100]; var ip = IPv4Packet.RandomPacket(); ip.PayloadPacket = udp; ip.SourceAddress = src; ip.DestinationAddress = dst; device.SendPacket(ip); } finally { device.Close(); } }
public void TestGetNextPacket() { var device = new WinDivertDevice { Filter = "!loopback and tcp" }; device.Open(); var capture = device.GetNextPacket(); device.Close(); AssertTcp(capture); }
public void TestCapture() { var device = new WinDivertDevice { Filter = "!loopback and tcp" }; device.Open(); var received = new List <RawCapture>(); device.OnPacketArrival += (s, e) => { received.Add(e.Packet); }; device.StartCapture(); Thread.Sleep(10000); device.StopCapture(); device.Close(); Assert.That(received, Has.Count.AtLeast(2)); foreach (var capture in received) { AssertTcp(capture); } }