js获取 mac地址

<html>

<head>

<title>JSgetMAC</title>

<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>

<metaname="generator"content="editplus"/>

<scriptevent="OnObjectReady(objObject,objAsyncContext)"for="foo">

if(objObject.IPEnabled!=null&&objObject.IPEnabled!="undefined"&&objObject.IPEnabled==true){

if(objObject.MACAddress!=null&&objObject.MACAddress!="undefined"&&objObject.DNSServerSearchOrder!=null)

MACAddr=objObject.MACAddress;

if(objObject.IPEnabled&&objObject.IPAddress(0)!=null&&objObject.IPAddress(0)!="undefined"&&objObject.DNSServerSearchOrder!=null)

IPAddr=objObject.IPAddress(0);

if(objObject.DNSHostName!=null&&objObject.DNSHostName!="undefined")

sDNSName=objObject.DNSHostName;

}

</script>

<scripttype="text/javascript">

varMACAddr;

varIPAddr;

varDomainAddr;

varsDNSName;

functioninit(){

varservice=locator.ConnectServer();

service.Security_.ImpersonationLevel=3;

service.InstancesOfAsync(foo,'Win32_NetworkAdapterConfiguration');

}

functiongetMac(){

document.getElementById('txtMac').value=unescape(MACAddr);

}

</script>

</head>

<bodyonLoad="init()">

<objectid="locator"classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6"VIEWASTEXT></object>

<objectid="foo"classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></object>

<inputtype="text"id="txtMac"/>

<inputtype="button"id="btn"value="Mac"onClick="getMac()"/>

</body>

</html>

相关推荐