Ton*_*nyM 8 c# sockets tcp raw-sockets
我正在尝试使用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());
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
问题是我在Wireshark跟踪中看不到任何内容.这就像Wireshark看到它的数据在堆栈中的距离不够远?如果我使用浏览器连接到192.168.0.198,Wireshark会显示所有数据包,但在我尝试使用上述代码和数据发送数据包时什么都不显示.
我的配置:
我作为管理员运行,所以这不是权限问题.
Windows7(未在VM中运行)
仅限无线连接(IP配置将其IP报告为192.168.0.140)
我究竟做错了什么?
我确信奥卡姆的剃刀适用于此,但我已经看了好几个小时,无法弄清楚出了什么问题.
| 归档时间: |
|
| 查看次数: |
1131 次 |
| 最近记录: |