JS获取客户端IP地址与机器名

获取机器名
<script   language=javascript>  
  var   WshShell   =new   ActiveXObject("WScript.Shell");  
  alert("计算机名   =   "+   WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%"));  
  alert("登录用户名   =   "+   WshShell.ExpandEnvironmentStrings("%USERNAME%"));  
  </script>  
 
===========================================================
代码如下:
<script language=javascript>
var WshShell =new ActiveXObject("WScript.Shell");
alert("计算机名 = "+ WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%"));
alert("登录用户名 = "+ WshShell.ExpandEnvironmentStrings("%USERNAME%"));
</script>
<script language=javascript>
var wshNetwork = new ActiveXObject("WScript.Network");
alert("域名       = "+ wshNetwork.UserDomain);
alert("计算机名   = "+ wshNetwork.ComputerName);
alert("登录用户名 = "+ wshNetwork.UserName);
</script>
千万要注意下面的设置,否则会出错误的。
要运行上述脚本,需要放宽IE的权限
需要下面选项内容
工具>Internet选项>安全>Internet>自定义级别>ActiveX控件和插件>对没有标记为安全的ActiveX控件进行初始化和脚本运行,
设置为启动。

-----------------------------------------------------------------------------------------------------------------------------

获取IP

<script language="JavaScript">
function GetLocalIPAddr(){
var oSetting = null;
var ip = null;
try{
oSetting = new ActiveXObject("rcbdyctl.Setting");
ip = oSetting.GetIPAddress;
alert(ip);
if (ip.length == 0){
return "没有连接到Internet";
}
oSetting = null;
}catch(e){
return ip;
}
return ip;
}
alert(GetLocalIPAddr())
</script>

你可能感兴趣的:(JavaScript,function,脚本,null,工具,internet)