index.html 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>js获取本机mac地址,IP地址,计算机名</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta content="MSHTML 6.00.2800.1106" name="GENERATOR">
  7. </head>
  8. <body>
  9. <object id=locator classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT></object>
  10. <object id=foo classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></object>
  11. <script language="JScript">
  12. var service = locator.ConnectServer();
  13. var MACAddr ;
  14. var IPAddr ;
  15. var DomainAddr;
  16. var sDNSName;
  17. service.Security_.ImpersonationLevel=3;
  18. service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
  19. </script>
  20. <script language="JScript" event="OnCompleted(hResult,pErrorObject, pAsyncContext)" for="foo">
  21. document.forms[0].txtMACAddr.value=unescape(MACAddr);
  22. document.all.txtIPAddr.value=unescape(IPAddr);
  23. document.forms[0].txtDNSName.value=unescape(sDNSName);
  24. //document.formbar.submit();
  25. </script>
  26. <script language="JScript" event="OnObjectReady(objObject,objAsyncContext)" for="foo">
  27. if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true) {
  28. if(objObject.MACAddress != null && objObject.MACAddress != "undefined") {
  29. MACAddr = objObject.MACAddress;
  30. }
  31. if(objObject.IPEnabled && objObject.IPAddress(0) != null && objObject.IPAddress(0) != "undefined") {
  32. IPAddr = objObject.IPAddress(0);
  33. }
  34. if(objObject.DNSHostName != null && objObject.DNSHostName != "undefined") {
  35. sDNSName = objObject.DNSHostName;
  36. }
  37. }
  38. </script>
  39. <form id="formfoo" name="formbar" action="#" method="post">
  40. <input value="00:05:5D:0E:C7:FA" name="txtMACAddr">
  41. <input value="10.241.91.51" name="txtIPAddr">
  42. <input value="typ" name="txtDNSName">
  43. </form>
  44. </body>
  45. </html>