简体   繁体   English

在C#中发送原始IP数据包,以太网层之上的所有内容

[英]Send Raw IP packet in C#, everything above the ethernet layer

I don't want to modify the ethernet portions of the frame, but I need to modify the IP packet and the data portion of the frame. 我不想修改帧的以太网部分,但我需要修改IP数据包和帧的数据部分。

I try sending a raw frame and it still puts in the IP information. 我尝试发送一个原始帧,它仍然输入IP信息。 I basically need to send a frame without defining the endpoint except in the bits I'm sending. 我基本上需要发送一个帧而不定义端点,除了我发送的位。

Here's what I got: 这是我得到的:

Socket s = new Socket(AddressFamily.Unspecified, SocketType.Raw, ProtocolType.Raw);
EndPoint ep = new IPEndPoint(IPAddress.Parse("205.188.100.58"),80);
s.SendTo(GetBytes(""),ep); //im sending nothing, so i expect the frame to just have ethernet stuff
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, false);

My question: Using SendTo adds the IP portion of the frame, I don't want that as I want to spoof the source IP. 我的问题:使用SendTo添加帧的IP部分,我不希望这样,因为我想欺骗源IP。 Using "Send" will crash because it says I need to specify an endpoint. 使用“发送”将崩溃,因为它说我需要指定一个端点。 Any suggestions on what to do? 有关该怎么办的任何建议? I just want to send a packet and define the IP section and data section myself. 我只是想发送一个数据包并自己定义IP部分和数据部分。

Note: No I'm not making a DOS attack, I need this for a legitimate use! 注意:不,我没有进行DOS攻击,我需要这个才能合法使用!

I know how to define the IP portion, its just a matter of actually sending the data without a generated IP portion. 我知道如何定义IP部分,它只是在没有生成IP部分的情况下实际发送数据。

Your question is very well answered here: How send raw ethernet packet with C#? 您的问题在这里得到了很好的回答: 如何使用C#发送原始以太网数据包?

Using Pcap.Net sort of a library, you can easily modify individual data packets in any way you want (as it uses the underlaying WinPcap implementation which is very powerful). 使用Pcap.Net排序库,您可以以任何方式轻松修改单个数据包(因为它使用了非常强大的底层WinPcap实现)。

You can also completely skip the IP layer and send to MAC addresses as in: http://www.codeproject.com/KB/IP/sendrawpacket.aspx where I used a similar approach to communicate with a micro-controller (Atmel ATmega) over Ethernet which provides almost realtime communications. 您还可以完全跳过IP层并发送到MAC地址,如: http//www.codeproject.com/KB/IP/sendrawpacket.aspx ,其中我使用类似的方法与微控制器通信(Atmel ATmega)通过以太网提供几乎实时的通信。

"Using Pcap.Net sort of a library, you can easily modify individual data packets in any way you want (as it uses the underlaying WinPcap implementation which is very powerful)." “使用Pcap.Net排序库,您可以以任何方式轻松修改单个数据包(因为它使用了非常强大的底层WinPcap实现)。”

Wrong! 错误! WinPcap cant do filtering/packet dropping/ create packet. WinPcap无法进行过滤/丢包/创建数据包。 By other words, its just lets you monitor the packet in an async fashion... 换句话说,它只是让你以异步方式监控数据包......

Raw packet /Promiscuous mode/ Driver filter / packet routing is another talk. 原始数据包/混杂模式/驱动程序过滤器/数据包路由是另一种说法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM