通过js获取计算机内网ip,计算机名,mac地址

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>test</title>
  6. <script type="text/javascript">
  7. var SOA_V_locator = null;
  8. var SOA_V_service = null;
  9. var SOA_V_loginenable = false;
  10. var SOA_V_NETINFO = null;
  11. var SOA_V_HOSTINFO = null;
  12. try{
  13. SOA_V_locator = new ActiveXObject ("WbemScripting.SWbemLocator");
  14. SOA_V_service = SOA_V_locator.ConnectServer(".");
  15. }catch(e){
  16. //alert("ErrInfoIS:"+e)
  17. }finally{
  18. }
  19. //获取网络连接信息
  20. function SOA_F_ipinfo(firstIf){
  21. if(SOA_V_service ==null){
  22. SOA_V_loginenable = false;
  23. SOA_F_alert("IE浏览器对SOA系统的支持比较好,请按照如下步骤设置IE浏览器后才能更好的访问本系统。<br>1.工具->Internet选项->进入选项卡的《安全》项->选中受信任站点,点击站点按钮,把http://soa.yundasys.com添加到受信任站点,点击关闭按钮。<br>2.工具->Internet选项->进入选项卡的《安全》项->选中自定义级别按钮,找到《ActiveX控件和插件》下的《对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本》项,选中《启用》即可,点击确定按钮。3.查看IE设置帮助</font></a>",firstIf);
  24. return;
  25. }else{
  26. SOA_V_loginenable = true;
  27. }
  28. }
  29. function SOA_F_alert(text_,firstIf){
  30. if(firstIf){
  31. var alertFram = document.createElement("DIV");
  32. alertFram.id="alertFram";
  33. alertFram.style.position = "absolute";
  34. alertFram.style.left = "50%";
  35. alertFram.style.top = "50%";
  36. alertFram.style.marginLeft = "-220px";
  37. alertFram.style.marginTop = "-100px";
  38. alertFram.style.width = "600px";
  39. alertFram.style.height = "300px";
  40. alertFram.style.background = "#fff";
  41. text_ = "<div>IE浏览器对SOA系统的支持比较好,请按照如下步骤设置IE浏览器后才能更好的访问本系统。<br>1.工具->Internet选项->进入选项卡的《安全》项->选中受信任站点,点击站点按钮,把http://xxxx添加到受信任站点,点击关闭按钮。<br>2.工具->Internet选项->进入选项卡的《安全》项->选中自定义级别按钮,找到《ActiveX控件和插件》下的《对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本》项,选中《启用》即可,点击确定按钮。<div>";
  42. strHtml = "<table boder='0' height='100%' width='100%' cellspacing='0' cellpadding='0'><tbody>";
  43. strHtml +="<tr><td style='background:#ffcc00;' width='100%' height='20px'>[系统提示]</td></tr>";
  44. strHtml +="<tr><td style='background:#FDEEF4;' height='8px' align='center'><input type='button' value='确 定' onclick='SOA_F_doOk()'</td></tr></tbody></table>";
  45. alertFram.innerHTML = strHtml;
  46. document.getElementsByTagName("body")[0].appendChild(alertFram);
  47. }else{
  48. $id("alertFram").style.display = "";
  49. }
  50. }
  51. function setClientInfo(){
  52. SOA_V_NETINFO = SOA_V_service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE"); //获取网络连接信息
  53. SOA_V_HOSTINFO = SOA_V_service.ExecQuery("SELECT * FROM Win32_Processor"); ////CPU 信息
  54. alert( getUserAgent()+getIpAddr()+getMacAddr()+getHost()); //浏览器以及版本 var user_Agent_Version = getUserAgentVersion();//浏览器版本
  55. //alert("浏览器以及版本:"+getUserAgent()+","+getUserAgentVersion()+",IP:"+getIpAddr()+",MAC地址:"+getMacAddr()+",计算机名称:"+getHost());
  56. }
  57. function setClientInfoDis(){
  58. setClientInfo();
  59. if(SOA_V_NETINFO != null){
  60. alert(getUserAgent());
  61. }else{
  62. alert("222222");
  63. }
  64. }
  65. //获取浏览器
  66. function getUserAgent(){
  67. //if(isIe()){
  68. //User_Agent = "IE浏览器";
  69. //}else if(isFireFox()){
  70. //User_Agent = "火狐浏览器";
  71. //}
  72. return navigator.userAgent; //包含以下属性中所有或一部分的字符串:appCodeName,appName,appVersion,language,platform
  73. }
  74. //获取浏览器版本
  75. function getUserAgentVersion(){
  76. var arrayObj = new Array();
  77. arrayObj = navigator.userAgent.split(";");
  78. return arrayObj[1];
  79. }
  80. //获取IP地址
  81. function getIpAddr(){
  82. var er = new Enumerator(SOA_V_NETINFO);
  83. var cmpipStr ="";
  84. for (;!er.atEnd();er.moveNext()){
  85. var p = er.item();
  86. var cmp_Ip = p.IPAddress(0);
  87. cmpipStr+=cmp_Ip+",";
  88. }
  89. //把字符串最后一个逗号替换为空格
  90. var str = cmpipStr.replace(/([^,]*),([^,]*)$/g, '$1$2');
  91. return str;
  92. }
  93. //获取MAC地址
  94. function getMacAddr(){
  95. var er = new Enumerator(SOA_V_NETINFO);
  96. var cmpmacStr ="";
  97. for (;!er.atEnd();er.moveNext ()){
  98. var p = er.item();
  99. var cmp_Mac = p.MACAddress;
  100. cmpmacStr += cmp_Mac+",";
  101. }
  102. //把字符串最后一个逗号替换为空格
  103. var str = cmpmacStr.replace(/([^,]*),([^,]*)$/g, '$1$2');
  104. return str;
  105. }
  106. //获取计算机名称
  107. function getHost(){
  108. var er2 = new Enumerator(SOA_V_HOSTINFO);
  109. for (;!er2.atEnd();er2.moveNext()) {
  110. var p = er2.item ();
  111. var cmp_Host = p.SystemName;
  112. }
  113. return cmp_Host;
  114. }
  115. //判断是否IE
  116. function isIe(){
  117. var i=navigator.userAgent.toLowerCase().indexOf("msie");
  118. return i>=0;
  119. }
  120. //判断是否firefox
  121. function isFireFox(){
  122. var i=navigator.userAgent.toLowerCase().indexOf("firefox");
  123. return i>=0;
  124. }
  125. </script>
  126. </head>
  127. <body marginheight="0" marginwidth="0">
  128. <a href="javascript:setClientInfoDis();" style=" text-decoration:none;color:red">test</a></div></td>

  129. </body>
  130. <script>
  131. setClientInfoDis();
  132. </script>
  133. </html>





posted @ 2016-05-25 21:26  九州浪子  阅读(...)  评论(...编辑  收藏