js to get MAC address in IE browser

<HTML>
<HEAD>
<TITLE>mac</TITLE>
<script type="text/javascript">
function load(){
var locator =new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled =True");
var e =new Enumerator (properties);
{
var p = e.item();
var mac = p.MACAddress;
document.getElementById("mac").value=mac;
}
}

</script>
</HEAD>  
<BODY οnlοad="load()">
<input type="text" id="mac" name="mac" />
</BODY>

</HTML>

 


In this way, a prompt will pop up when running in IE, whether to allow this kind of interaction. The mac address can only be obtained after confirmation.

In "Tools-->Internet Options--> Security -->Custom Level" " Initialize and script ActiveX controls that are not marked as executable safe scripts " is enabled, and there will be no prompts, but this is another There are security concerns. I don't know what better way to do it.

This method can only be used in IE, I don't know how to get it in other browsers.

Guess you like

Origin blog.csdn.net/u010174217/article/details/47144761