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 ChangeValues() { var packet = IPv4Packet.RandomPacket(); packet.Id = 12345; Assert.AreEqual(12345, packet.Id); }
public void RandomPacket() { IPv4Packet.RandomPacket(); }