Javascript


MAC Address Using WMI on Internet Explorer
By Umar Farooq
05-Aug-08
Views: 96507

This article helps you in finding the MAC address of a client machine on IE using WMI Library
 
MAC Address Using WMI on Internet Explorer (Page 1 of 1)
In this little article, i will help you in finding the MAC address from javascript with the help of WMI Library. The script runs only on IE with the following limitations
  • Works on Internet Explorer only
  • Internet Explorer security settings should allow creating ActiveX Objects
  • WMI scripting library is installed on the client machine
Setting IE Security Level
First of all you will need to change the security settings of IE, allowing the following two options
  • Initialize and script ActiveX controls not marked as safe for script -> Set it to enable or prompt
  • Run ActiveX controls and plugins -> Set it to enable or prompt
To change these two options, go to Tools -> Internet Options -> Security -> Custom Level Screen Shot1  Screen Shot2

Installing WMI scripting library
The next step is to install WMI Library, you can download it for free from the Microsoft website. WMI Library can be downloaded from
http://www.microsoft.com/downloads/details.aspx?FamilyID=6430f853-1120-48db-8cc5-f2abdc3ed314&displaylang=en

What is WMI scripting library?
The WMI scripting library provides the set of automation objects through which scripting languages, such as VBScript, JScript, and ActiveState ActivePerl access the WMI infrastructure. The WMI scripting library is implemented in a single automation component named wbemdisp.dll that physically resides in the systemroot\System32\Wbem directory. (description from microsoft.com)
Read More >>

SWbemLocator
At the top of the WMI scripting library object model is the SWbemLocator object. SWbemLocator is used to establish an authenticated connection to a WMI namespace, much as the VBScript GetObject function and the WMI moniker "winmgmts:" are used to establish an authenticated connection to WMI. However, SWbemLocator is designed to address two specific scripting scenarios that cannot be performed using GetObject and the WMI moniker.(description from microsoft.com) Read More >>

The whole script is given below, just copy this script and execute in IE only.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Getting MAC Address From Javascript(IE Only)</title>
 
<script language="javascript">
function showMacAddress(){
 
	var obj = new ActiveXObject("WbemScripting.SWbemLocator");
	var s = obj.ConnectServer(".");
	var properties = s.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
	var e = new Enumerator (properties);

 
	var output;
	output='<table border="0" cellPadding="5px" cellSpacing="1px" bgColor="#CCCCCC">';
	output=output + '<tr bgColor="#EAEAEA"><td>Caption</td><td>MACAddress</td></tr>';
	while(!e.atEnd())

	{
		e.moveNext();
		var p = e.item ();
		if(!p) continue;
		output=output + '<tr bgColor="#FFFFFF">';
		output=output + '<td>' + p.Caption; + '</td>';
		output=output + '<td>' + p.MACAddress + '</td>';
		output=output + '</tr>';
	}

	output=output + '</table>';
	document.getElementById("box").innerHTML=output;
}
</script>
 
</head>
<body>
	<input type="button" value="Show MAC Address" onclick="showMacAddress()" />

	<div id="box">
	</div>
</body>
</html>
 

Have you ever tried converting a JQuery plugin (slider, menu, news ticker etc) into a PHP class? Implementing a JQuery plugin like this has a lot of benefits if you have to use the same plugin in more than one projects/websites. This article discusses the benefits of this technique . Read More Integrating JQuery/JavaScript with PHP

Comments
sree
[08-Jul-2009]
#1

hi, Script is very good and working fine. But i would like to display one MAC Id, which is unique in any system. How can i get? Thanks and Regards sree

šelik šatı
[16-Jul-2009]
#2

WOW, lol this is working fine, but question to "do you want to work it?" This is wonderful!

fasc
[01-Aug-2009]
#3

Hi. This script work great. I dont know if is possible to write this for others browsers. what language i have to use for make this in other browser?

deva
[06-Oct-2009]
#4

I need mac address using php...And it has to work all os.please...........

smithveg
[06-Nov-2009]
#5

It does work for my IE7

GhOsT
[20-Nov-2009]
#6

@deva Impossible! PHP is a server side language it cant access the MAC address of a client.

Julio
[12-Jan-2011]
#7

Hi Tk is very good.....excelent, one question Print Text in Object ActivexObject is possible ???? 

zawaruddin
[25-Feb-2011]
#8

hm.. great..

btw could u get MAC Address Using WMI on other browser???

thank's b4... ^_^

popovich
[15-Mar-2011]
#9

It works ok, but the line "e.moveNext();" needs to be at the end of the while block, otherwise it will skip the first item on the list.

tractari
[01-May-2011]
#10

On firefox doesn't work?

Tractari bucuresti
[21-Jun-2011]
#11

Need any external ActiveX controls?

gugan
[17-Aug-2011]
#12

it is not working in ie8 the following error is comming 

Microsoft JScript runtime error: Automation server can't create object

 

Abhi
[26-Oct-2011]
#13

Has anyone been able to put all this data in form fileds and do a POST to a server ? I would like to save tihs data on the server side to make sure it is the same machinea accessing my system after purchasing a license.

madhusoodhanenlru
[30-Nov-2011]
#14

Thanks in advance....i am getting an error like "Automation Server can't create object " plz help.....

adithya
[07-Mar-2012]
#15

Great !! it is working . Anybody know how to get MAC address by running a javascript , at the same time without the setting "Initialize and script ActiveX controls not marked as safe for script "-> Set it to enable or prompt

Md Ali
[20-May-2012]
#16

Hi,

When I run this code on my local machine, its working fine, but when I publish it to any hosting site, then it not working.

Why?

Please help me on this matter.

mika
[10-Sep-2012]
#17

wow it worked thanks alot

Sandeep DiL
[09-Feb-2013]
#18

I have tested that script and it doesn't work for me..

Tested result
Opera v12.13 => Not working

Mozilla v18.0.2 => Not Working

Chrome v24.0.1312.57 => Not Working

IE v10.0.9200 => Not Working

Is short  ..... NOT WORKING..................................................

tushar
[19-Feb-2013]
#19

can I get mac address in C# .Net and in codeigniter????????????????

????????

please rly me as fast as you can.....

celik konstruksiyon
[24-Feb-2013]
#20

very thanks...

Jahangir Khan
[25-May-2013]
#21

The script is very good, but i need this script to work in all kind of explorers, specially Google Chrome and Fire fox. Please define this script for all explorers. Thanks.

Posting comments has been disabled temporarily