Method one (only for IE and the client's IE allows Acitivex to run, through the platform: xp,server03,2000):
Gets the client IP.
- <HTML>
- <HEAD>
- <title>getlocalip</title>
- </HEAD>
- <BODY>
- Get IP:
- <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>
- </BODY>
- </HTML>
Method Two (all platforms and browsers):
Get the IP that the client is in the network, provided that the customer is networked.
- <html>
- <head>
- <Meta http-equiv= "content-type" content= "text/html; charset=gb2312 ">
- <title>javascript get client ip[using Sina interface]</title>
- </head>
- <body>
- <script type="Text/javascript" src="http://counter.sina.com.cn/ip/" charset=" gb2312 "></script> <!--Get interface data, note CharSet
- <script type="Text/javascript">
- Document.writeln ("IP address:" +ildata[0]+ "<br />"); The IP address in the output interface data
- Document.writeln ("Address type:" +ildata[1]+ "<br />"); The type of IP address in the output interface data
- Document.writeln ("Address type:" +ildata[2]+ "<br />"); The provinces and municipalities of the IP addresses in the output interface data
- Document.writeln ("Address type:" +ildata[3]+ "<br />"); Of the IP address in the output interface data.
- Document.writeln ("Address type:" +ildata[4]+ "<br />"); The operator of the IP address in the output interface data
- </Script>
- </body>
- </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.
- <HTML>
- <HEAD>
- <title>wmi Scripting HTML</title>
- </HEAD>
- <BODY>
- <script language=javascript>
- var wshshell =new ActiveXObject ("Wscript.Shell");
- document.write ("Computer name =" + wshshell.expandenvironmentstrings ("%computername%") + "<br/>");
- document.write ("Login username =" + wshshell.expandenvironmentstrings ("%USERNAME%") + "<br/>");
- </Script>
- </BODY>
- </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).
- <HTML>
- <HEAD>
- <title>wmi Scripting HTML</title>
- </HEAD>
- <BODY>
- <script language=javascript>
- var wshnetwork = new ActiveXObject ("Wscript.Network");
- document.write ("Domain name =" + wshnetwork.userdomain+ "<br/>");
- document.write ("Computer name =" + wshnetwork.computername+ "<br/>");
- document.write ("Login username =" + wshnetwork.username+ "<br/>");
- </Script>
- </BODY>
- </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).
- <html>
- <head>
- <title></title>
- </head>
- <body>
- <object classid=" Clsid:76a64158-cb41-11d1-8b02-00600806d9b6 " id=" locator " style=" Display:none; Visibility:hidden "></object >
- <object classid="clsid:75718c9a-f029-11d1-a1ac-00c04fb6c223" id= "foo" style=" Display:none;visibility:hidden "></object>
- <form name="MyForm">
- <BR/>mac Address:<input type="text" name="macAddress">
- <BR/>IP Address:<input type="text" name="ipAddress">
- <br/> hostname:<input type="text" name="HostName">
- </form>
- </body>
- </html>
- <script language="javascript">
- var smacaddr="";
- var sipaddr="";
- var sdnsname="";
- var service = Locator. ConnectServer ();
- Service. Security_. Impersonationlevel=3;
- Service. Instancesofasync (foo, ' Win32_NetworkAdapterConfiguration ');
- </Script>
- <script for="foo" event="OnObjectReady (objobject,objasynccontext)" language=" JScript ">
- if (objobject.ipenabled! = NULL && objobject.ipenabled! = "undefined" && objobject.ipenabled = = True ){
- if (objobject.ipenabled && objobject.ipaddress (0)!=null && objobject.ipaddress (0)! = "undefined")
- sipaddr = objobject.ipaddress (0);
- if (objobject.macaddress! = null &&objobject.macaddress! = "undefined")
- smacaddr = objobject.macaddress;
- if (objobject.dnshostname! = null &&objobject.dnshostname! = "undefined")
- sdnsname = objobject.dnshostname;
- }
- </Script>
- <script for="foo" event="oncompleted (Hresult,perrorobject, Pasynccontext)" language= "JScript">
- Myform.macaddress.value=smacaddr;
- Myform.ipaddress.value=sipaddr;
- Myform.hostname.value=Sdnsname;
- </Script>
JS get IP, mac and host name of several methods