Get Client MAC Address & IP Address using Javascript
This
is somewhat similar to the previous post Get client cpu id with
javascript, so the client still needs to enable ActiveX components on
his browser. Read more on the said post for details.
Ok if you're done reading, you'll notice we simply change the script to this:
<script type="text/javascript">
var macAddress = "";
var ipAddress = "";
var computerName = "";
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}");
e = new Enumerator(wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True"));
for(; !e.atEnd(); e.moveNext()) {
var s = e.item();
macAddress = s.MACAddress;
ipAddress = s.IPAddress(0);
computerName = s.DNSHostName;
}
</script>
Instead
of Win32_Processor, here we'll access Win32_NetworkAdapterConfiguration
to read network related details like the MAC Address, IP Address and
the computer name.
Then we can simply use textboxes to display that information or whatever you like.
<input type="text" id="txtMACAdress" />
<input type="text" id="txtIPAdress" />
<input type="text" id="txtComputerName" />
<script type="text/javascript">
document.getElementById("txtMACAdress").value = unescape(macAddress);
document.getElementById("txtIPAdress").value = unescape(ipAddress);
document.getElementById("txtComputerName").value = unescape(computerName);
</script>
And
just like before, make sure to place the declarations snippet above
this script for it to display the values properly. Now the client can
see his/her own MAC and IP Addresses.
Read more about the Win32_NetworkAdapterConfiguration object here http://msdn.microsoft.com/en-us/library/aa394217(VS.85).aspx
Copyright © 2011 - All Rights Reserved - Softron.in
Template by Softron Technology