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
-k
Thursday, February 11, 2010
Get Client MAC Address & IP Address using Javascript
Labels:
activex,
computer name,
html,
ip address,
javascript,
mac address
Subscribe to:
Post Comments (Atom)
UPDATED:
ReplyDeleteSet query to "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True" to get only active values.
Very Helpful !!
ReplyDelete"automation server can't create object" error occured
ReplyDelete"automation server can't create object" error occured
ReplyDeleteautomation server can't create object" error occured
ReplyDeleteplease enable everything related to active X in internet options->local intranet->costum
DeleteAutomation server can't create object
ReplyDeleteIf "Automation server can't create object" error occurs, go to Tools -> Internet Options, Security tab -> Custom level and enable "Initialize and script ActiveX controls not marked as safe for scripting" setting.
ReplyDeletei made that but is still couldnt create object
DeleteGetObject("winmgmts:{impersonationLevel=impersonate}") dose not work
DeleteThis is only useful where the client and server have a trusted relationship. On the general web this simply won't work.
ReplyDeleteAlso only useful on Windows clients!!!
ReplyDeleteWill it work on a linux machine?
ReplyDelete^ I don't think so, because the object (Win32) we try to access here is for Windows.
ReplyDeleteSo how did Kamkar do it at the hacker con then eh?
ReplyDeletehttp://www.securityweek.com/hacker-uses-xss-and-google-streetview-data-determine-physical-location
Obviously he must have found a way to do the impossible.
uh.. thats the mac address of the last router passing the packets not the computer requesting the web page
ReplyDeletethis will work perfect
ReplyDeleteps.ramkumar@gmail.com
function HttpRequest(){
var pageRequest = false //variable to hold ajax object
/*@cc_on
@if (@_jscript_version >= 5)
try {
pageRequest = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try {
pageRequest = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e2){
pageRequest = false
}
}
@end
@*/
if (!pageRequest && typeof XMLHttpRequest != 'undefined')
pageRequest = new XMLHttpRequest()
if (pageRequest){ //if pageRequest is not false
pageRequest.open('GET', "http://checkip.dyndns.org", false) //get page synchronously
pageRequest.send(null)
if (window.location.href.indexOf("http")==-1 || request.status==200)
//document.write(request.responseText)
alert(request.responseText);
extractIP(new String(request.responseText));
}
}
function extractIP(testString){
split = testString.split(":");
nextSpl = split[1].split("<");
document.getElementById("txtIPAdress").value = unescape(nextSpl[0]);
}
not working at my end please help me the regarding
DeleteI dont understand how you can actually use Javascript to retrieve remote users mac address without them activating ActiveX controls?
ReplyDeleteThanks a lot!
ReplyDeleteVery helpful and exactly what I needed! :)
How do we get mac address if the browser is Firefox?
ReplyDeleteDid you find something, i have the same problem...
ReplyDeleteHi,
ReplyDeleteIt is working fine during debug mode, but after hosting the application, its not work . why?
can anyone help me about this?
take ghanta
ReplyDeleteNice try. If you could get a clients mac address with javascript that would be an egregious security hole and we would all be forced to turn off javascript support in our browsers.:(
ReplyDeleteYou would have to write a plug in (non IE) or an activeX control (IE) to do that sort of thing.
Getting the client's gateway IP is easy with a request.servervariables at the server so there is little need to do it via javascript.
Please write plugin for working in nonIE or IE
ReplyDeleteif need contact to sonntcil@yahoo.com
I have just create plugin that can operate on CHROME, IE, FIREFOX , MAC OSX 10.6 above
can you post the plug in
Deleteit´s only for windows?
ReplyDeletepls can i get a complete script, the above script is not working. pls pls
ReplyDeleteNO
DeleteWell it isn't possible,usually.Also, you probably shouldn't care. The Java Script code found on internet is not compatible with internet explorer(IE8) .
ReplyDeleteThanks
Silvester Norman
Change Mac Address
hi,
ReplyDeleteit is not working in mozilla firefox .....any solution for run active x object in firefox ???
can we get mac address with out using activeX using javascript ? if yes then how
ReplyDeleteWill this work for cell phones? Not very well. The best we might be able to do is find the nearest cell tower at the time of use.
ReplyDeleteWhat about ubuntu users
ReplyDeleteWHAT IS UBANTU???
Deletehi, I have a problem ('GetObject' is undefined) using this code somebody could help me to resolve this
ReplyDeletebut what about getting mac address of smart tv programming javascript??
Deletebut what about getting mac address of smart tv programming javascript??
ReplyDeleteWhat you're saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I'm sure you'll reach so many people with what you've got to say.
ReplyDeleteHow to create OBB folder for OBB file
ReplyDeleteRead more here How to CREATE OBB FOLDER FOR OBB FILE ANDROID GAME
Naijabiggies
InfoClickNigeria
Rev HVBUZZ
Thank you for the share. You are helping others to grow their knowledge by sharing such a valuable information very helpful
ReplyDeleteThanks
ReplyDeleteHi, How to get client IP address in IE? Please anyone help me with this. Thanks a lot in advance
ReplyDeleteno one will help you...pray to god
Deletexzczxczxczx
ReplyDeleteFactorial Program in Python
ReplyDeleteDjango Simple File Upload
How to convert MySQL query result to JSON in Python
Login with LinkedIn in PHP
PHP IMAP
This comment has been removed by the author.
Delete