zoukankan      html  css  js  c++  java
  • 获取局域网内部机器的MAC地址

    [DllImport("Iphlpapi.dll")]
        private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
        [DllImport("Ws2_32.dll")]
        private static extern Int32 inet_addr(string ip);

        static private Int64 getremotemac(string localip, string remoteip)
        {

            Int32 ldest = inet_addr(remoteip);   //目的地的ip 
            Int32 lhost = inet_addr(localip);   //本地服务器的ip 

            try
            {
                Int64 macinfo = new Int64();
                Int32 len = 6;
                int res = SendARP(ldest, 0, ref   macinfo, ref   len);
                return macinfo;
            }
            catch (Exception err)
            {
                Console.WriteLine("error:{0}", err.Message);
            }
            return 0;
        }

        private void Page_Load(object sender, System.EventArgs e)
        {
            string userip = Request.UserHostAddress;
            //Int32 ldest = inet_addr(userip); //目的地的ip
            //Int32 lhost = inet_addr(" "); //本地服务器的ip
            this.userinfo.Text = Convert.ToString(getremotemac(" ", userip)) ;
        }

  • 相关阅读:
    单分发器
    Python 虚拟环境
    $modal
    memoization
    directive例子2
    UI-Router
    angular-translate
    directive例子1
    FileInputStream/FileOutputStream的应用
    自定义readLine
  • 原文地址:https://www.cnblogs.com/tianguook/p/1944563.html
Copyright © 2011-2022 走看看