A seguir, são apresentadas várias maneiras de obter endereços de URL por JS
A cópia do código é a seguinte:
theurl = document.url;
thishref = document.location.href;
thissloc = self.Location.href;
thisdloc = document.Location;
thistloc = top.location.href;
thisploc = parent.document.location;
thisthost = top.Location.HostName;
thisHost = location.hostname;
tmphpage = thishref.split ("/");
thishpage = tmphpage [tmphpage.length-1];
tmpupage = theurl.split ("/");
thisupage = tmpupage [tmpupage.length-1];
A seguir, é apresentado o método para usar o JS para obter o endereço MAC, o endereço IP e o nome do host:
A cópia do código é a seguinte:
<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 = "Locor" Style = "Display: Nenhum; visibilidade: Hidden"> </ject>
<Object ClassID = "CLSID: 75718C9A-F029-11D1-A1AC-00C04FB6C223" ID = "Foo" Style = "Display: Nenhum; visibilidade: Hidden"> </ject>
<nome name = "myform">
<br/> Endereço MAC: <input type = "text" name = "macaddress">
<br/> Endereço IP: <input type = "text" name = "ipaddress">
<br/> Nome do host: <input type = "text" name = "hostname">
</morm>
</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 para = "foo" event = "onobjectiony (objobject, objasyncContext)" idioma = "jscript">
if (objobject.ipeNabled! = null && objobject.ipeNabled! = "indefinido" && objobject.ipeNabled == true) {
if (objobject.ipeNabled && objobject.ipaddress (0)! = null && objobject.ipaddress (0)! = "indefinido")
sipaddr = objobject.ipaddress (0);
if (objobject.macaddress! = null && objobject.macaddress! = "indefinido")
smacaddr = objobject.macaddress;
if (objobject.dnshostname! = null && objobject.dnshostname! = "indefinido")
sdnsname = objobject.dnshostName;
}
</script>
<script para = "foo" event = "onCompleted (hresult, perrorObject, pasynccontext)" idioma = "jscript">
myform.macaddress.value = smacaddr;
myform.ipaddress.value = sipaddr;
myform.hostname.value = sdnsname;
</script>