我们之前做过个项目也是 要获取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);
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