Разбор TCP пакета - C#

Узнай цену своей работы

Формулировка задачи:

Подскажите я нашел примеры на C# но там надо подключать PcapDotNet. Можно ли без него собрать ICMP пакет самостоятельно по байтам. Если у кого были примеры буду признателен.
Листинг программы
  1. static void Main(string[] args)
  2. {
  3. // Retrieve the device list from the local machine
  4. IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;
  5. if (allDevices.Count == 0)
  6. {
  7. Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");
  8. return;
  9. }
  10. // Print the list
  11. for (int i = 0; i != allDevices.Count; ++i)
  12. {
  13. LivePacketDevice device = allDevices[i];
  14. Console.Write(String.Format("{0}. {1}", (i + 1), device.Name));
  15. if (device.Description != null)
  16. Console.WriteLine(String.Format(" ({0})", device.Description));
  17. else
  18. Console.WriteLine(" (No description available)");
  19. }
  20. int deviceIndex = 0;
  21. do
  22. {
  23. Console.WriteLine(String.Format("Enter the interface number (1-{0}):", allDevices.Count));
  24. string deviceIndexString = Console.ReadLine();
  25. if (!int.TryParse(deviceIndexString, out deviceIndex) ||
  26. deviceIndex < 1 || deviceIndex > allDevices.Count)
  27. {
  28. deviceIndex = 0;
  29. }
  30. } while (deviceIndex == 0);
  31. // Take the selected adapter
  32. PacketDevice selectedDevice = allDevices[deviceIndex - 1];
  33. // Open the output device
  34. using (PacketCommunicator communicator = selectedDevice.Open())
  35. {
  36. communicator.SendPacket(BuildTcpPacket());
  37. }
  38. Console.ReadKey();
  39. }
  40. private static Packet BuildTcpPacket()
  41. {
  42. EthernetLayer ethernetLayer =
  43. new EthernetLayer
  44. {
  45. Source = new MacAddress("00:25:22:50:ef:74"),
  46. Destination = new MacAddress("02:02:02:02:02:02"),
  47. EtherType = EthernetType.None, // Will be filled automatically.
  48. };
  49. IpV4Layer ipV4Layer =
  50. new IpV4Layer
  51. {
  52. Source = new IpV4Address("192.168.1.203"), // <- this is my LAN IP ADDRESS IS TRUE??
  53. CurrentDestination = new IpV4Address("192.168.1.35"), // <-- THIS IS MY SERVER IPADDESS??
  54. Fragmentation = IpV4Fragmentation.None,
  55. HeaderChecksum = null, // Will be filled automatically.
  56. Identification = 64,
  57. Options = IpV4Options.None,
  58. Protocol = null, // Will be filled automatically.
  59. Ttl = 64,
  60. TypeOfService = 0,
  61. };
  62. TcpLayer tcpLayer =
  63. new TcpLayer
  64. {
  65. SourcePort = 9509,
  66. DestinationPort = 80,
  67. Checksum = null, // Will be filled automatically.
  68. SequenceNumber = 100,
  69. AcknowledgmentNumber = 50,
  70. ControlBits = TcpControlBits.Acknowledgment,
  71. Window = 100,
  72. UrgentPointer = 0,
  73. Options = TcpOptions.None,
  74. };
  75. PayloadLayer payloadLayer =
  76. new PayloadLayer
  77. {
  78. Data = new Datagram(Encoding.ASCII.GetBytes("hello world")),
  79. };
  80. PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, tcpLayer);
  81. return builder.Build(DateTime.Now);
  82. }

Решение задачи: «Разбор TCP пакета»

textual
Листинг программы
  1. Source = new IpV4Address("192.168.1.203"), // <- this is my LAN IP ADDRESS
  2. CurrentDestination = new IpV4Address("192.168.1.35"), // <-- THIS IS MY SERVER IPADDESS??

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

7   голосов , оценка 3.714 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут