如何通过ASP.NET应用程序中的java脚本WMI对象读取客户端PC的MAC ID [英] How do I read client PC's MAC ID through java script WMI object in ASP.NET application

查看:93
本文介绍了如何通过ASP.NET应用程序中的java脚本WMI对象读取客户端PC的MAC ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求是,用户应该从特定系统登录。为此,我将客户端PC的MAC地址保存到我的数据库中。当用户尝试登录时,Web应用程序应获取客户端PC的MAC ID并验证数据库值。如果匹配,将允许用户登录。是否可以通过WMI对象读取客户端PC的MAC ID?



我尝试过:



var macAddress =;

var ipAddress =;

var computerName = 。;

var wmi = GetObject(winmgmts:{impersonationLevel = impersonate,(Systemtime)}!//+ computerName +/ root / cimv2);

e = new Enumerator(wmi.ExecQuery(SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True));

for(;!e.atEnd(); e.moveNext()){

var s = e.item();

macAddress = s.MACAddress;

ipAddress = s.IPAddress(0);

computerName = s.DNSHostName;

}

Requirement is, the user should log in from specific system. For this I am saving client PC's MAC Address into my database. When user will try to login, the web application should get MAC ID of Client PC and verify with database value. If it matches, user will be allowed to log in. Is it possible to read client PC's MAC id through WMI Object?

What I have tried:

var macAddress = "";
var ipAddress = "";
var computerName = ".";
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate, (Systemtime)}!//" + computerName + "/root/cimv2");
e = new Enumerator(wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True"));
for (; !e.atEnd() ; e.moveNext()) {
var s = e.item();
macAddress = s.MACAddress;
ipAddress = s.IPAddress(0);
computerName = s.DNSHostName;
}

推荐答案

你不能这样做。访问客户端硬件是对服务器(ASP.NET)上运行的代码和浏览器中运行的代码(javascript)的禁止。



另外,A MAC地址不是系统唯一的。 MAC是网络子网上的网络接口所独有的。



您可以拥有多个NIC,使用相同的MAC地址从世界各地访问您的站点,相同的城市,在同一家公司,甚至在公司内部。



如果笔记本电脑有多个NIC,每个都有自己的MAC,那该怎么办?是的,这很常见。如果笔记本电脑连接到有线网络,当他们拔出电缆并切换到无线网络时,MAC地址会有所不同,甚至将机器放在带有自己的NIC和另一个MAC地址的扩展坞中。 />


要为计算机ID,您需要在客户端上安装证书。您可能还必须拥有自己的证书服务器。



如果这有点多,生成GUID值并将其发送到客户端进行存储在一个cookie中。是的,cookie可以被清除,所以你必须自己评估它是否可以接受。
You can't do this. Access to client hardware is off-limits to the code running on the server (ASP.NET) and to code running in the browser (javascript).

Also, A MAC Address is NOT unique to a system. MAC's are unique to a network interface on a network subnet.

You CAN have multiple NIC's with the same MAC address accessing your site from various locations around the world, in the same cities, in the same companies, even inside your company premises.

What about the case where laptops have multiple NIC's, each with their own MAC? Yes, it's quite common. If a laptop is connected to a wired network, the MAC address is going to be different when they pull that cable out and switch to wireless network, or even drop the machine in a dock with it's own NIC and yet another MAC address.

To ID a machine, you'd need to install a certificate on the client. You'd probably have to have your own certificate server dolling these out too.

If that's a little much, generate a GUID value and send that to the client to store in a cookie. Yes, cookies can be cleared, so that's something you'd have to evaluate for yourself to see if its acceptable.


这篇关于如何通过ASP.NET应用程序中的java脚本WMI对象读取客户端PC的MAC ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆