//// <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控件
源碼下載地址:http://download.csdn.net/source/354589。
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/cocosoft/archive/2008/02/17/2100144.aspx