注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

一路奔跑

奔跑着一路向前...

 
 
 

日志

 
 

JavaScript 取客户端ip,MAC,主机名  

2011-09-28 10:26:24|  分类: JavaScript |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

<HTML>      
<HEAD><TITLE>JS取IP地址MAC地址</TITLE>      
    <META http-equiv=Content-Type content="text/html; charset=gb2312">      
    <SCRIPT language=JScript event="OnCompleted(hResult,pErrorObject, pAsyncContext)" for=foo>      
         document.forms[0].txtMACAddr.value = unescape(MACAddr);      
         document.forms[0].txtIPAddr.value = unescape(IPAddr);      
         document.forms[0].txtDNSName.value = unescape(sDNSName);      
         //document.formbar.submit();      
    </SCRIPT>      
     
    <SCRIPT language=JScript event=OnObjectReady(objObject,objAsyncContext) for=foo>      
         if (objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true)      
         {      
             if (objObject.MACAddress != null && objObject.MACAddress != "undefined")      
                MACAddr = objObject.MACAddress;      
             if (objObject.IPEnabled && objObject.IPAddress(0) != null && objObject.IPAddress(0) != "undefined")      
                IPAddr = objObject.IPAddress(0);      
             if (objObject.DNSHostName != null && objObject.DNSHostName != "undefined")      
                sDNSName = objObject.DNSHostName;      
         }      
    </SCRIPT>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>      
</HEAD>      
<BODY>      
<OBJECT id=locator classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT></OBJECT>      
<OBJECT id=foo classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></OBJECT>      
<SCRIPT language=JScript>      
     var service = locator.ConnectServer();      
     var MACAddr ;      
     var IPAddr ;      
     var DomainAddr;      
     var sDNSName;      
    service.Security_.ImpersonationLevel = 3;      
     service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');      
</SCRIPT>      
     
<FORM id="formfoo" name="formbar" action="index.do" method="post">      
    <INPUT name="txtMACAddr"> <br>      
    <INPUT name="txtIPAddr"><br>      
    <INPUT name="txtDNSName"></FORM>      
</BODY>      
</HTML>
      
<script>
// 方法2
//alert("本例子读硬盘号\n")
v=new ActiveXObject("MSScriptControl.ScriptControl.1");
v.Language="VBScript";
//本例子读硬盘号
var code =
'Function rtnphysicaldisk()\r\n'
              + 'DIM objphysicaldisk\r\n'
              + 'strComputer = "."\r\n'
              + 'Set objWMIService = GetObject("winmgmts://./root/cimv2")\r\n'
              + 'Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive")\r\n'
              + 'For Each objItem in colItems\r\n'
     + 'objphysicaldisk= objItem.Model\r\n'
              + 'Next\r\n'
     + 'rtnphysicaldisk = objphysicaldisk\r\n'
              + 'End Function';
v.AddCode(code);
var x=v.eval("rtnphysicaldisk");
alert(x);
/*
//本例子读MAC地址
var code =
'Function rtnphysicaldisk()\r\n'
              + 'DIM objphysicaldisk\r\n'
              + 'strComputer = "."\r\n'
              + 'Set objWMIService = GetObject("winmgmts://./root/cimv2")\r\n'
              + 'Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")\r\n'
              + 'For Each objItem in colItems\r\n'
     + 'objphysicaldisk= objItem.MACAddress \r\n'
              + 'Next\r\n'
     + 'rtnphysicaldisk = objphysicaldisk\r\n'
              + 'End Function';
v.AddCode(code);
var x=v.eval("rtnphysicaldisk");
var y=x.replace(":","").replace(":","").replace(":","").replace(":","").replace(":","");
alert(x+"\n"+y);
*/


</script>

  评论这张
 
阅读(237)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018