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)) ;
        }

  • 相关阅读:
    编译安装linux内核步骤
    怎样在github上协同开发
    在JSP里使用CKEditor和CKFinder
    tomcat结合nginx使用小结
    JAVA学习笔记——(五)
    JAVA学习笔记——(四)
    JAVA学习笔记——(三)
    JAVA学习笔记——(二)
    JAVA学习笔记——(一)
    ansible
  • 原文地址:https://www.cnblogs.com/tianguook/p/1944563.html
Copyright © 2011-2022 走看看