gpt4 book ai didi

c# - 为什么我不能发送这个 IP 数据包?

转载 作者:可可西里 更新时间:2023-11-01 02:31:00 29 4
gpt4 key购买 nike

我正在尝试使用 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(未在虚拟机中运行)

  • 仅无线连接(IP 配置报告其 IP 为 192.168.0.140)

我做错了什么?

我确定奥卡姆 Razor 在这里适用,但我已经看了好几个小时了,但无法弄清楚哪里出了问题。

最佳答案

This question , backed up by MSDN ,声称 Windows 不再(XP SP 2 到 7)允许使用原始套接字传输 TCP 数据。

关于c# - 为什么我不能发送这个 IP 数据包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10549163/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com