JavaScript获取客户端IP及MAC
1<HTML><HEAD><TITLE>WMI Scripting HTML</TITLE>
2<META http-equiv=Content-Type content="text/html; charset=gb2312">
3<SCRIPT language=JScript event="OnCompleted(hResult,pErrorObject, pAsyncContext)" for=foo>
4document.forms[0].txtMACAddr.value=unescape(MACAddr);
5document.forms[0].txtIPAddr.value=unescape(IPAddr);
6document.forms[0].txtDNSName.value=unescape(sDNSName);
7//document.formbar.submit();
8</SCRIPT>
9
10<SCRIPT language=JScript event=OnObjectReady(objObject,objAsyncContext) for=foo>
11if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true)
12{
13if(objObject.MACAddress != null && objObject.MACAddress != "undefined")
14MACAddr = objObject.MACAddress;
15if(objObject.IPEnabled && objObject.IPAddress(0) != null && objObject.IPAddress(0) != "undefined")
16IPAddr = objObject.IPAddress(0);
17if(objObject.DNSHostName != null && objObject.DNSHostName != "undefined")
18sDNSName = objObject.DNSHostName;
19}
20</SCRIPT>
21
22<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
23<BODY>
24<OBJECT id=locator classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT></OBJECT>
25<OBJECT id=foo classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></OBJECT>
26<SCRIPT language=JScript>
27var service = locator.ConnectServer();
28var MACAddr ;
29var IPAddr ;
30var DomainAddr;
31var sDNSName;
32service.Security_.ImpersonationLevel=3;
33service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
34</SCRIPT>
35
36<FORM id=formfoo name=formbar action=NICPost.asp method=post><INPUT value=00:05:5D:0E:C7:FA name=txtMACAddr> <INPUT value=192.168.0.2 name=txtIPAddr> <INPUT value=typ name=txtDNSName> </FORM></BODY></HTML>
37
核心就是调用了两个系统自带的ActiveX进行交互.
有空可以试一下。
本文来自博客园,作者:CarlZeng,转载请注明原文链接:https://www.cnblogs.com/backuper/archive/2008/11/27/1342300.html
需求沟通链接 扫客服加群: