博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于获取客户端Mac地址
阅读量:7057 次
发布时间:2019-06-28

本文共 1444 字,大约阅读时间需要 4 分钟。

private static string GetClientMAC()        {            string mac_dest = string.Empty;            try            {                string strClientIP = HttpContext.Current.Request.UserHostAddress.ToString().Trim();                Int32 ldest = inet_addr(strClientIP); //目的地的ip                 Int32 lhost = inet_addr("");   //本地服务器的ip                 Int64 macinfo = new Int64();                Int32 len = 6;                int res = SendARP(ldest, 0, ref macinfo, ref len);                string mac_src = macinfo.ToString("X");                while (mac_src.Length < 12)                {                    mac_src = mac_src.Insert(0, "0");                }                for (int i = 0; i < 11; i++)                {                    if (0 == (i % 2))                    {                        if (i == 10)                        {                            mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2));                        }                        else                        {                            mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2));                        }                    }                }            }            catch (Exception ex)            {                Log.Error("GetClientMAC", ex);                //throw ex;            }            return mac_dest;        }

 

上面的代码只能在局域网中使用,在广域网中是拿不到mac的(00-00-00-00-00-00),而且运行时间较长。

转载于:https://www.cnblogs.com/shikyoh/p/8350087.html

你可能感兴趣的文章
epoll的作用和原理介绍
查看>>
服务器远程监控管理(一)-硬件篇
查看>>
Android permission 工具类
查看>>
Tomcat使用与配置
查看>>
接口与抽象类的区别(转)
查看>>
转载:分析apk工具aapt的使用,解析其原理
查看>>
如何向视图插入数据
查看>>
注册和策略模式
查看>>
python 列表
查看>>
第七课作业
查看>>
MEAN实践——LAMP的新时代替代方案(下)
查看>>
CentOS7 下安装 Oracle 12c
查看>>
简单介绍AngularJs Filters
查看>>
Dubbo下一站:Apache顶级项目
查看>>
我说分布式事务之最大努力通知型事务
查看>>
挖机全车无动作是什么故障原因引起的?
查看>>
监狱电视系统设计原则及应用场景
查看>>
JDK 源码阅读 :ByteBuffer
查看>>
python面试题
查看>>
vscode 使用小结
查看>>