zoukankan      html  css  js  c++  java
  • SendArp获取MAC地址

            [DllImport("Iphlpapi.dll")]
            static extern int SendARP(Int32 DestIP, Int32 SrcIP, ref Int64 MacAddr, ref Int32 PhyAddrLen);

            [DllImport("Ws2_32.dll")]
            static extern Int32 inet_addr(string ipaddr);

            //SendArp获取MAC地址
            public static string GetMacAddress(string macip)
            {
                StringBuilder strReturn = new StringBuilder();
                try
                {
                    Int32 remote = inet_addr(macip);

                    Int64 macinfo = new Int64();
                    Int32 length = 6;
                    SendARP(remote, 0, ref macinfo, ref length);

                    string temp = System.Convert.ToString(macinfo, 16).PadLeft(12, '0').ToUpper();

                    int x = 12;
                    for (int i = 0; i < 6; i++)
                    {
                        if (i == 5) { strReturn.Append(temp.Substring(x - 2, 2)); }
                        else { strReturn.Append(temp.Substring(x - 2, 2) + ":"); }
                        x -= 2;
                    }

                    return strReturn.ToString();
                }
                catch
                {
                    return strReturn.ToString();
                }
            }

  • 相关阅读:
    CodeForces
    EOJ 3506. 斐波那契数列
    牛客练习赛13 D幸运数字Ⅳ . 康托逆展开
    UVA
    Piggy-Bank HDU
    Dollar Dayz POJ
    UVA 674 Coin Change (完全背包)
    python OOP (1)
    python lambda简易使用
    python whl模块安装方法
  • 原文地址:https://www.cnblogs.com/mossan/p/749844.html
Copyright © 2011-2022 走看看