Разбор TCP пакета - C#
Формулировка задачи:
Подскажите я нашел примеры на C# но там надо подключать PcapDotNet. Можно ли без него собрать ICMP пакет самостоятельно по байтам. Если у кого были примеры буду признателен.
static void Main(string[] args) { // Retrieve the device list from the local machine IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { Console.WriteLine("No interfaces found! Make sure WinPcap is installed."); return; } // Print the list for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; Console.Write(String.Format("{0}. {1}", (i + 1), device.Name)); if (device.Description != null) Console.WriteLine(String.Format(" ({0})", device.Description)); else Console.WriteLine(" (No description available)"); } int deviceIndex = 0; do { Console.WriteLine(String.Format("Enter the interface number (1-{0}):", allDevices.Count)); string deviceIndexString = Console.ReadLine(); if (!int.TryParse(deviceIndexString, out deviceIndex) || deviceIndex < 1 || deviceIndex > allDevices.Count) { deviceIndex = 0; } } while (deviceIndex == 0); // Take the selected adapter PacketDevice selectedDevice = allDevices[deviceIndex - 1]; // Open the output device using (PacketCommunicator communicator = selectedDevice.Open()) { communicator.SendPacket(BuildTcpPacket()); } Console.ReadKey(); } private static Packet BuildTcpPacket() { EthernetLayer ethernetLayer = new EthernetLayer { Source = new MacAddress("00:25:22:50:ef:74"), Destination = new MacAddress("02:02:02:02:02:02"), EtherType = EthernetType.None, // Will be filled automatically. }; IpV4Layer ipV4Layer = new IpV4Layer { Source = new IpV4Address("192.168.1.203"), // <- this is my LAN IP ADDRESS IS TRUE?? CurrentDestination = new IpV4Address("192.168.1.35"), // <-- THIS IS MY SERVER IPADDESS?? Fragmentation = IpV4Fragmentation.None, HeaderChecksum = null, // Will be filled automatically. Identification = 64, Options = IpV4Options.None, Protocol = null, // Will be filled automatically. Ttl = 64, TypeOfService = 0, }; TcpLayer tcpLayer = new TcpLayer { SourcePort = 9509, DestinationPort = 80, Checksum = null, // Will be filled automatically. SequenceNumber = 100, AcknowledgmentNumber = 50, ControlBits = TcpControlBits.Acknowledgment, Window = 100, UrgentPointer = 0, Options = TcpOptions.None, }; PayloadLayer payloadLayer = new PayloadLayer { Data = new Datagram(Encoding.ASCII.GetBytes("hello world")), }; PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, tcpLayer); return builder.Build(DateTime.Now); }
Решение задачи: «Разбор TCP пакета»
textual
Листинг программы
Source = new IpV4Address("192.168.1.203"), // <- this is my LAN IP ADDRESS CurrentDestination = new IpV4Address("192.168.1.35"), // <-- THIS IS MY SERVER IPADDESS??
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д