我正在尝试使用 C# 发送 IP 数据包。
destAddress = IPAddress.Parse("192.168.0.198"),
destPort = 80;
// Create a raw socket to send this packet
rawSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
// Bind the socket to the interface specified
IPEndPoint iep = new IPEndPoint(IPAddress.Parse("192.168.0.140"),0);
rawSocket.Bind(iep);
// Set the HeaderIncluded option since we include the IP header
rawSocket.SetSocketOption( socketLevel, SocketOptionName.HeaderIncluded, 1 );
// Send the packet!
int rc = rawSocket.SendTo(builtPacket, new IPEndPoint(destAddress, destPort));
Console.WriteLine("sent {0} bytes to {1}", rc, destAddress.ToString());
builtPacket的内容如下所示。这是一个包含 TCP SYN 数据包的 IP 数据包(我想这就是我创建的)。
45 00 00 28 00 00 00 00 02 06 36 6E C0 A8 00 8C
C0 A8 00 C6 14 1E 00 50 00 00 00 00 00 00 00 00
05 02 FF FF E6 4F 00 00
输出是:
sent 40 bytes to 192.168.0.198
问题是我在 Wireshark 跟踪中没有看到任何内容。好像数据在堆栈中的位置不够远,Wireshark 无法看到?如果我使用浏览器连接到 192.168.0.198,Wireshark 会显示所有数据包,但当我尝试使用上述代码和数据发送数据包时,不会显示任何内容。
我的配置:
我究竟做错了什么?
我确信奥卡姆剃刀适用于此,但我已经研究了几个小时,但无法找出问题所在。