|
发表于 2020-8-7 13:00:01
|
显示全部楼层
下面的做法参考一下。另外不需要255个线程,有一个线程扫描就可以了。255个线程光创建和调度就要消耗很多系统资源,可能是性能不高的一个原因哦!
public class CLsArp
{
#region APIs
[DllImport("iphlpapi.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern Int32 SendARP(UInt32 udwDestIP,UInt32 udwSrcIP,byte[] pMacAddr,ref Int32 PhyAddrLen);
private const Int32 NUMBER_OF_PHYSICAL_ADDRESS_BYTES = 6;
#endregion
public CLsArp()
{
}
public static byte[] GetComputerMacAddr(UInt32 dwIP)
{
byte[] abMacAddr = null;
Int32 dwPhyAddrLen = 0;
try
{
abMacAddr = new byte[NUMBER_OF_PHYSICAL_ADDRESS_BYTES];
dwPhyAddrLen = abMacAddr.Length;
if (SendARP(dwIP,0,abMacAddr, ref dwPhyAddrLen) != 0)
{
//Get Error!Reset byte array to null
abMacAddr = null;
}
}
catch
{
abMacAddr = null;
}
return abMacAddr;
}
}
|
|