|
Refer to the following practices. In addition, there is no need for 255 threads, just one thread scan. The creation and scheduling of 255 threads will consume a lot of system resources, which may be a reason for the low performance!
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;
To
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;
}
} |
|