在Mozilla中获取MAC地址,ActiveXObject不起作用 [英] Getting MAC Address in Mozilla, ActiveXObject is not working

查看:334
本文介绍了在Mozilla中获取MAC地址,ActiveXObject不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var locator = new ActiveXObject(WbemScripting.SWbemLocator); 
var service = locator.ConnectServer(。);
var properties = service.ExecQuery(SELECT * FROM Win32_NetworkAdapterConfiguration);
var e = new Enumerator(properties);
var MACaddress ='';
alert(它的内部); (;!e.atEnd(); e.moveNext()){
var p = e.item();
if(p.MACAddress){
MACaddress = MACaddress + p.MACAddress +',';
}
}
MACaddress = MACaddress.substring(0,MACaddress.length - 1);
MACaddress = replaceAll(MAC地址,':',' - ');
location.href = location.href +'?CAT = MAC& MACAddr ='+ MAC地址;

这个函数在IE中工作正常,但是在第一行本身就是Mozilla Firefox。我将 locator.ConnectServer(。)更改为 locator.ConnectServer(MACHINE),但仍然无法在Mozilla Firefox中使用。


现在的浏览器沙箱(或者试图)一切都是这样的:出于安全原因在浏览器中进行。沙箱防止任何直接访问系统,包括。文件系统,硬件等(这并不意味着浏览器不与硬件通信,但作为用户,我们没有直接访问它)。

IE是只有浏览器支持ActiveX(这是微软自己的技术),但它不应该依靠相同的原因,(主要是)安全性。



如果你想要将MAC地址用于某种唯一的标识符/安全性,您可以查看新的网络加密API ,但是,在写这篇文章的时候,它仍然处于草稿模式,并且没有得到广泛的支持(但将是,或者意图在未来的某个时间跨浏览器),所以可能不是非常有用的建议在任何情况下,您都可以使用服务器端根据各种因素生成一个唯一的标识符,并使用cookie或localStorage等方式将其存储在本地浏览器中。

var locator = new ActiveXObject("WbemScripting.SWbemLocator");
            var service = locator.ConnectServer(".");
            var properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
            var e = new Enumerator(properties);
            var MACaddress = '';
            alert("Its Inside");
            for (; !e.atEnd(); e.moveNext()) {
                var p = e.item();
                if (p.MACAddress) {
                    MACaddress = MACaddress + p.MACAddress + ',';
                }
            }
            MACaddress = MACaddress.substring(0, MACaddress.length - 1);
            MACaddress = replaceAll(MACaddress, ':', '-');
            location.href = location.href + '?CAT=MAC&MACAddr=' + MACaddress;

This function is working fine in IE but its breaking in mozilla firefox at the first line itself. I changed locator.ConnectServer(".") to locator.ConnectServer("MACHINE") but still its not working in Mozilla Firefox.

解决方案

Simple answer: you can't.

Modern browsers sandboxes (or try to) everything that goes on in the browser for security reason. Sand-boxing prevents any direct access to a system incl. files system, hardware etc. (it doesn't mean the browser does not communicate with the hardware but as users we have not direct access to it).

IE is the only browser which supports ActiveX (which is Microsoft's own technology) but it shouldn't be relied upon for the same reason, (mainly..) security.

If you want to use the MAC-address for some sort of unique identifier/security you can instead look into the new Web Cryptography API, however, at the time of this writing it is still in draft mode and not widely supported (but will be, or intents to be, cross-browser sometime in the future) so perhaps not so very useful advice at the moment.

You can in any case use server side to generate a unique identifier based on various factors and store it locally in the browser using either cookies or localStorage and so forth.

这篇关于在Mozilla中获取MAC地址,ActiveXObject不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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