I have an scenario in my web application that need to find out the MAC address of the client by either java script or server side code.
Please help me to resolve this issue.
Thanks, Tamilselvan S.
I have an scenario in my web application that need to find out the MAC address of the client by either java script or server side code.
Please help me to resolve this issue.
Thanks, Tamilselvan S.
Client IP address or client MAC address? The first one can be retrieved by using Page.Request.UserHostAddress. The second problem (MAC address) is slightly more complicated and you need to use WMI. You need to create an object in JavaScript, query the WMI and pass the information back to the server. In addition you need to allow access to unsigned ActiveX in IE. Try the below one.
<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>