什麼都不說了。看代碼:
/**//// <summary>
/// 取Mac地址
/// </summary>
/// <param name="DestIP">目標IP</param>
/// <param name="SrcIP">源IP</param>
/// <param name="pMacAddr">Mac地址</param>
/// <param name="PhyAddrLen">Mac地址的長度</param>
/// <returns></returns>
[DllImport("iphlpapi.dll", ExactSpelling = true)]
public static extern int SendARP(int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen);
取Mac地址源碼:
IPAddress ip = null;
try
...{
ip = IPAddress.Parse(textBox1.Text);//textBox1是輸入IP地址的文本框
}
catch
...{
MessageBox.Show("請勿輸入非法IP地址", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
byte[] b = new byte[6];
int len = b.Length;
int r = SendARP((int)ip.Address, 0, b, ref len);
label2.Text = "MAC地址為:" + BitConverter.ToString(b, 0, 6);//label2為顯示Mac地址的label控件