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系统中/和是什么意思,和window系统有什么区别?
    给自己的U盘设定图标
    我的第一篇文章
    大端小端
    好玩的地图
    英语流利说 第28天
    英语流利说 第27天
    英语流利说 第26天
    英语流利说 第25天
    英语流利说 第24天
  • 原文地址:https://www.cnblogs.com/tianguook/p/1944563.html
Copyright © 2011-2022 走看看