C# 取MAC地址

//// <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

發佈了3 篇原創文章 · 獲贊 1 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章