JS get IP, mac and host name of several methods

Source: Internet
Author: User
Tags get ip

Method one (only for IE and the client's IE allows Acitivex to run, through the platform: xp,server03,2000):

Gets the client IP.

  1. <HTML>
  2. <HEAD>
  3. <title>getlocalip</title>
  4. </HEAD>
  5. <BODY>
  6. Get IP:
  7. <ScriptLanguage="JavaScript"> Function getlocalipaddr () {varosetting = null; var  ip = null; try{  osetting = new activexobject ("Rcbdyctl. Setting "),  ip = osetting.getipaddress;  if  (ip.length == 0) { return  "Not connected to the Internet";  }  osetting = null; }catch (e) {  Return ip; } return ip; } document.write (GETLOCALIPADDR () + " <br/> ")  </ Script>   
  8. </BODY>
  9. </HTML>

Method Two (all platforms and browsers):

Get the IP that the client is in the network, provided that the customer is networked.

  1. <html>
  2. <head>
  3. <Meta http-equiv= "content-type" content= "text/html; charset=gb2312 ">
  4. <title>javascript get client ip[using Sina interface]</title>
  5. </head>
  6. <body>
  7. <script type="Text/javascript" src="http://counter.sina.com.cn/ip/" charset=" gb2312 "></script> <!--Get interface data, note CharSet
  8. <script type="Text/javascript">
  9. Document.writeln ("IP address:" +ildata[0]+ "<br />"); The IP address in the output interface data
  10. Document.writeln ("Address type:" +ildata[1]+ "<br />"); The type of IP address in the output interface data
  11. Document.writeln ("Address type:" +ildata[2]+ "<br />"); The provinces and municipalities of the IP addresses in the output interface data
  12. Document.writeln ("Address type:" +ildata[3]+ "<br />"); Of the IP address in the output interface data.
  13. Document.writeln ("Address type:" +ildata[4]+ "<br />"); The operator of the IP address in the output interface data
  14. </Script>
  15. </body>
  16. </html>

Method three (only for IE and the client's IE allows Acitivex to run):

Call the VBS script to get the computer name (some people do not know what the computer name is, the simple explanation is that it is the physical name of the machine instead of the user name you are using) and the login username.

  1. <HTML>
  2. <HEAD>
  3. <title>wmi Scripting HTML</title>
  4. </HEAD>
  5. <BODY>
  6. <script language=javascript>
  7. var wshshell =new ActiveXObject ("Wscript.Shell");
  8. document.write ("Computer name =" + wshshell.expandenvironmentstrings ("%computername%") + "<br/>");
  9. document.write ("Login username =" + wshshell.expandenvironmentstrings ("%USERNAME%") + "<br/>");
  10. </Script>
  11. </BODY>
  12. </HTML>



Method Four (ie only and the client's IE allows Acitivex to run):

Get the computer name, login username, and domain name (if you join a domain, it shows you which domain the machine is in).

  1. <HTML>
  2. <HEAD>
  3. <title>wmi Scripting HTML</title>
  4. </HEAD>
  5. <BODY>
  6. <script language=javascript>
  7. var wshnetwork = new ActiveXObject ("Wscript.Network");
  8. document.write ("Domain name =" + wshnetwork.userdomain+ "<br/>");
  9. document.write ("Computer name =" + wshnetwork.computername+ "<br/>");
  10. document.write ("Login username =" + wshnetwork.username+ "<br/>");
  11. </Script>
  12. </BODY>
  13. </HTML>



Method Five (ie only and the client's IE allows Acitivex to run):

Ability to get to LAN IP address, native Mac, and machine name (code source network).

    1. <html>
    2. <head>
    3. <title></title>
    4. </head>
    5. <body>
    6. <object classid=" Clsid:76a64158-cb41-11d1-8b02-00600806d9b6 " id=" locator " style=" Display:none; Visibility:hidden "></object >  
    7. <object classid="clsid:75718c9a-f029-11d1-a1ac-00c04fb6c223" id= "foo" style=" Display:none;visibility:hidden "></object>
    8. <form name="MyForm">
    9. <BR/>mac Address:<input type="text" name="macAddress">
    10. <BR/>IP Address:<input type="text" name="ipAddress">
    11. <br/> hostname:<input type="text" name="HostName">
    12. </form>
    13. </body>
    14. </html>
    15. <script language="javascript">
    16. var smacaddr="";
    17. var sipaddr="";
    18. var sdnsname="";
    19. var service = Locator.  ConnectServer ();
    20. Service. Security_.  Impersonationlevel=3;
    21. Service. Instancesofasync (foo, ' Win32_NetworkAdapterConfiguration ');
    22. </Script>
    23. <script for="foo" event="OnObjectReady (objobject,objasynccontext)" language=" JScript ">
    24. if (objobject.ipenabled! = NULL && objobject.ipenabled! = "undefined" && objobject.ipenabled = = True ){  
    25. if (objobject.ipenabled && objobject.ipaddress (0)!=null && objobject.ipaddress (0)! = "undefined")
    26. sipaddr = objobject.ipaddress (0);
    27. if (objobject.macaddress! = null &&objobject.macaddress! = "undefined")
    28. smacaddr = objobject.macaddress;
    29. if (objobject.dnshostname! = null &&objobject.dnshostname! = "undefined")
    30. sdnsname = objobject.dnshostname;
    31. }
    32. </Script>
    33. <script for="foo" event="oncompleted (Hresult,perrorobject, Pasynccontext)" language= "JScript">
    34. Myform.macaddress.value=smacaddr;
    35. Myform.ipaddress.value=sipaddr;
    36. Myform.hostname.value=Sdnsname;
    37. </Script>

JS get IP, mac and host name of several methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.