在C#中发送原始IP数据包,以太网层之上的所有内容 [英] Send Raw IP packet in C#, everything above the ethernet layer

查看:992
本文介绍了在C#中发送原始IP数据包,以太网层之上的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想修改帧的以太网部分,但我需要修改IP数据包和帧的数据部分。

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. I basically need to send a frame without defining the endpoint except in the bits I'm sending.

这是我得到的:

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);

我的问题:
使用SendTo添加IP部分框架,我不希望因为我想欺骗源IP。使用发送将崩溃,因为它说我需要指定一个端点。关于该怎么做的任何建议?我只是想发送一个数据包并自己定义IP部分和数据部分。

My question: Using SendTo adds the IP portion of the frame, I don't want that as I want to spoof the source 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.

注意:不,我没有进行DOS攻击,我需要这个是合法的使用!

Note: No I'm not making a DOS attack, I need this for a legitimate use!

我知道如何定义IP部分,它只是在没有生成IP部分的情况下实际发送数据。

I know how to define the IP portion, its just a matter of actually sending the data without a generated IP portion.

推荐答案

你的问题在这里得到了很好的回答:如何使用C#发送原始以太网数据包?

Your question is very well answered here: How send raw ethernet packet with C#?

使用 Pcap.Net 类库,你可以用你想要的任何方式轻松修改单个数据包(因为它使用了非常强大的底层WinPcap实现)。

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).

您还可以完全跳过IP层并发送到MAC地址,如下所示: http://www.codeprojec t.com/KB/IP/sendrawpacket.aspx 我使用类似的方法通过以太网与微控制器(Atmel ATmega)进行通信,提供几乎实时的通信。

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.

这篇关于在C#中发送原始IP数据包,以太网层之上的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆