c# - C#中的ARP请求

标签 c# wifi pinvoke arp spoofing

我试图让我的 Android 设备认为我是路由器,使用 C# 中的简单 ARP 请求(使用 C# 将 arp 从我的笔记本电脑发送到我的 android 设备)。 我认为如果我将使用 SendArp 方法(来自 Iphlpapi.dll),它将起作用:

SendArp(ConvertIPToInt32(IPAddress.Parse("myAndroidIP")), 
   ConvertIPToInt32(IPAddress.Parse("192.168.1.1")), macAddr, ref macAddrLen)

但我无法发送请求。*但是,如果我将写入“0”而不是 ConvertIPToInt32(IPAddress.Parse("192.168.1.1")):

SendArp(ConvertIPToInt32(IPAddress.Parse("myAndroidIP")), 0, 
    macAddr, ref macAddrLen)

它会起作用:

enter image description here

因此,如果源 ip 是“0”,它就可以工作,但如果源是路由器 IP 地址,则不是。

我正在使用这种 pinvoke 方法发送 ARP:

[System.Runtime.InteropServices.DllImport("Iphlpapi.dll", EntryPoint = "SendARP")]
internal extern static Int32 SendArp(Int32 destIpAddress, Int32 srcIpAddress,
byte[] macAddress, ref Int32 macAddressLength);

以及将字符串 IP 转换为 Int32 的方法:

private static Int32 ConvertIPToInt32(IPAddress pIPAddr)
{
 byte[] lByteAddress = pIPAddr.GetAddressBytes();
 return BitConverter.ToInt32(lByteAddress, 0);
}

谢谢。

最佳答案

我认为你误解了第二个参数的意思。

1) ARP 请求不是发送到特定 IP(例如 Android 设备),而是广播到网络中的所有计算机。

2) 查看SendARP function的描述,第二个参数是接口(interface)IP,不是目的IP。如果我没理解错的话,如果你的电脑里有多张网卡,你可以选择一张发送ARP请求

SrcIP [in] The source IPv4 address of the sender, in the form of an IPAddr structure. This parameter is optional and is used to select the interface to send the request on for the ARP entry. The caller may specify zero corresponding to the INADDR_ANY IPv4 address for this parameter.

关于c# - C#中的ARP请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17132941/

相关文章:

android - 如何获取请求者 - android 中配置的 WiFi 网络的 BSSID?

c# - 如何在没有 WMI 的情况下获取在远程计算机上运行的进程的所有者

c# - 在编译查询中包含 "offline"代码

c# - Mono.Math.BigInteger 由于其保护级别而无法访问

c# - 当你将一个参数传递给下一个参数时你怎么调用它

asp.net - 与 Silverlight 5 的串行通信(COM 端口)

c# - 我能否在 .NET 程序集中嵌入 win32 DLL,并使用 P/Invoke 对其进行调用?

c# - 将具有多列的 GridView 显示为两组列

java - 如何使用java套接字通过两个不同的wifi连接两台电脑?

ios - 如何快速获取wifi网络的RSSI值?