The following describes how to obtain URL addresses in JS:
Copy codeThe Code is as follows:
ThisURL = document. URL;
ThisHREF = document. location. href;
ThisSLoc = self. location. href;
ThisDLoc = document. location;
ThisTLoc = top. location. href;
ThisPLoc = parent.doc ument. location;
ThisTHost = top. location. hostname;
ThisHost = location. hostname;
TmpHPage = thisHREF. split ("/");
ThisHPage = tmpHPage [tmpHPage. length-1];
TmpUPage = thisURL. split ("/");
ThisUPage = tmpUPage [tmpUPage. length-1];
The following describes how to use JS to obtain the MAC address, IP address, and host name:
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gbk">
</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/> Host name: <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>