How to get
MAC Address using java Script Asp.net c#
Note : This
will work in IE only not for other browsers
.
Steps
to Enable Active X in the IE
Click Tools -->
Internet Options --> In Security Tab --> Click Trusted Sites --> Insecurity Level of zone
Disable the
(Enable Protected Mode) --> Click Custom Level Button --> Enable the (Initialize and script ActiveX
control not marked as safe for scripting )
<script type="text/javascript">
$(document).ready(function () {
alert(GetMacAddress());
function GetMacAddress() {
//This
function requires following option to be enabled without prompting
//In
Internet Options for IE 5.5 Minimum & Max to latest and up
//Tab
Security (Local Internet Sites)
//Custom
Level button
//"Initialize
and script ActiveX control not marked as safe." option enabled
try {
var locator = new ActiveXObject("WbemScripting.SWbemLocator");
var service =
locator.ConnectServer(".");
//Get
properties of the network devices with an active IP address
var properties =
service.ExecQuery("SELECT * FROM
Win32_NetworkAdapterConfiguration" +
" WHERE IPEnabled=TRUE");
var e = new Enumerator(properties);
//Take first item from the list and return MACAddress
var p = e.item(0);
var s = e.item();
macAddress = s.MACAddress;
ipAddress = s.IPAddress(0);
computerName = s.DNSHostName;
alert("macAddress= " +
macAddress + " ipAddress = " + ipAddress + "
computerName = " + computerName)
}
catch (exception) {
alert('Add your domain to Trusted Sites.');
window.location = "about:blank";
}
return p.MACAddress;
}
});
</script>
No comments:
Post a Comment