我正在尝试使用 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 会显示所有数据包,但当我尝试使用上述代码和数据发送数据包时,什么也不显示。
我的配置:
我以管理员身份运行,所以这不是权限问题。
Windows7(不在虚拟机中运行)
Wireless connection only (IP config reports its IP as 192.168.0.140)
What am I doing wrong?
I'm sure Occam's Razor applies here, but I've been looking at this for hours and can't figure out what's wrong.