<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