从C#开始,我想做相同的以下内容:
arp -a |findstr 192.168.1.254
Run Code Online (Sandbox Code Playgroud)
或者,答案可以调用SendARP函数并获得结果.
这将允许我的应用程序执行一些需要MAC地址的其他处理.
jop*_*jop 26
SendARP P/Invoke是这样的:
[DllImport("iphlpapi.dll", ExactSpelling=true)]
public static extern int SendARP( int destIp, int srcIP, byte[] macAddr, ref uint physicalAddrLen );
Run Code Online (Sandbox Code Playgroud)
PInvoke.NET有这个例子:
IPAddress dst = IPAddress.Parse("192.168.2.1"); // the destination IP address
byte[] macAddr = new byte[6];
uint macAddrLen = (uint)macAddr.Length;
if (SendARP(BitConverter.ToInt32(dst.GetAddressBytes(), 0), 0, macAddr, ref macAddrLen) != 0)
throw new InvalidOperationException("SendARP failed.");
string[] str = new string[(int)macAddrLen];
for (int i=0; i<macAddrLen; i++)
str[i] = macAddr[i].ToString("x2");
Console.WriteLine(string.Join(":", str));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19506 次 |
| 最近记录: |