首页 新闻 会员 周边

asp.net 获取客户端硬盘sn mac

0
悬赏园豆:50 [待解决问题]

单位现需要客户端或许硬盘sn、mac地址、看了一些js做的例子,感觉不是很好,容易出错误,因为内网使用,可以设置成信任站点,安全性不是问题,如果能用axtiveX做不错,请高手指点,谢谢!

Ronnie Sun的主页 Ronnie Sun | 初学一级 | 园豆:150
提问于:2010-11-10 00:47
< >
分享
所有回答(2)
0

我们之前做过个项目也是 要获取SN,MAC 等信息。就是通过 JS来做的。

        var locator = new ActiveXObject("WbemScripting.SWbemLocator");
        var service = locator.ConnectServer();

        var hdi = new Enumerator(service.ExecQuery("SELECT Caption, DeviceID,Signature FROM Win32_DiskDrive")).item();
        alert(hdi.Caption);
        alert(hdi.DeviceID);
        alert(hdi.Signature);

HUHU慈悲 | 园豆:9973 (大侠五级) | 2010-11-10 08:53
1
1 using System;
2
3  using System.Data;
4
5 using System.Configuration;
6
7 using System.Web;
8
9 using System.Web.Security;
10
11 using System.Web.UI;
12
13 using System.Web.UI.WebControls;
14
15 using System.Web.UI.WebControls.WebParts;
16
17 using System.Web.UI.HtmlControls;
18
19 //引入相应的空间信息
20
21 using System.Text.RegularExpressions;
22
23 using System.Diagnostics;
24
25 public partial class _Default : System.Web.UI.Page
26
27 {
28
29 protected void Page_Load(object sender, EventArgs e)
30
31 {
32
33 //此处输入Ip地址,你可以做成接受文本框的值进行查询
34
35 Response.Write(GetCustomerMac("192.168.168.242"));
36
37 }
38
39
40
41 //这里是关键函数了
42
43 public string GetCustomerMac(string IP)
44
45 {
46
47 string dirResults="";
48
49 ProcessStartInfo psi = new ProcessStartInfo();
50
51 Process proc = new Process();
52
53 psi.FileName = "nbtstat";
54
55 psi.RedirectStandardInput = false;
56
57 psi.RedirectStandardOutput = true;
58
59 psi.Arguments = "-a " + IP;
60
61 psi.UseShellExecute = false;
62
63 proc = Process.Start(psi);
64
65 dirResults = proc.StandardOutput.ReadToEnd();
66
67 proc.WaitForExit();
68
69
70
71 //匹配mac地址
72
73 Match m = Regex.Match(dirResults, "\\w+\\-\\w+\\-\\w+\\-\\w+\\-\\w+\\-\\w\\w");
74
75 //若匹配成功则返回mac,否则返回找不到主机信息
76
77 if (m.ToString() != "")
78
79 {
80
81 return m.ToString();
82
83 }
84
85 else
86
87 {
88
89 return "找不到主机信息";
90
91 }
92
雪莱·亨尼格 | 园豆:524 (小虾三级) | 2010-11-10 08:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册