获取 客户端的MAC地址

收藏本信息编号:235 发布时间:2009-07-28 截止日期: 地区:

使用代码获取 客户端的MAC地址
方便网站获取一个用户电脑的唯一标识;统计访问的机器的情况

 1#region 获取客户端MAC地址
 2    /// <summary>
 3    /// 获取客户端MAC地址
 4    /// </summary>
 5    /// <returns></returns>

 6    private string GetMac()
 7    {
 8        string MAC = "";
 9        ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration");
10        ManagementObjectCollection MOC = MC.GetInstances();
11        foreach (ManagementObject moc in MOC)
12        {
13            if (moc["IPEnabled"].ToString() == "True")
14            {
15                MAC = moc["MacAddress"].ToString();
16            }

17        }

18        return MAC;
19    }

20
21
22    public string GetCustomerMac(string IP) //para IP is the client's IP
23    {
24        if (IP == "127.0.0.1")
25        {
26            return GetMac();
27        }
//"00-04-61-5C-31-52";//00-0F-1F-C6-B2-B3 
28        else
29        {
30            string dirResults = "";
31            ProcessStartInfo psi = new ProcessStartInfo();
32            Process proc = new Process();
33            psi.FileName = "nbtstat";
34            psi.RedirectStandardInput = false;
35            psi.RedirectStandardOutput = true;
36            psi.Arguments = "-A " + IP;
37            psi.UseShellExecute = false;
38            proc = Process.Start(psi);
39            dirResults = proc.StandardOutput.ReadToEnd();
40            proc.WaitForExit();
41            dirResults = dirResults.Replace(" """).Replace(" """).Replace("\t""");
42            int i = dirResults.LastIndexOf("=");
43            dirResults = dirResults.Substring(i + 217);
44            if (dirResults.IndexOf("本地连接"!= -1)
45            { dirResults = "没有得到mac"; }
46            return dirResults;
47        }

48    }

49
50
51
52    #endregion
 
 

发布人信息

[错误报告] [推荐] [收藏][打印] [关闭] [返回顶部]

当前共有0人发表了评论.

推荐信息

最新信息