且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#中发送ARP请求以及要使用的库

更新时间:2023-01-01 19:24:23

我假设您要欺骗 ARP 回复 . ARP 是一种链路层(L2)协议.要从用户模式在此层欺骗数据包,需要使用原始套接字(通常是TCP/负责此工作的内核中的IP堆栈.

I'm assuming you want to spoof ARP replies. ARP is a Link Layer (L2) protocol. To spoof packets at this layer from user mode requires using Raw Sockets (as it is usually the TCP/IP stack in the kernel who takes care of this).

换句话说,您不会在Windows中使用任何常见的/健全机制在C#中执行此操作.

In other words, you're not going to do it on Windows in C# with any sort of common / sane mechanism.

SendARP 可以使用Win32 API调用,但仅出于合法目的而存在:

The SendARP Win32 API call is available, but it is only there for this legitimate purpose:

...发送地址解析协议(ARP)请求以获取与指定的目标IPv4地址相对应的物理地址

... sends an Address Resolution Protocol (ARP) request to obtain the physical address that corresponds to the specified destination IPv4 address

(这些原因并非微不足道.)

(There's a reason these things are not trivial.)