<div name="intelliTxt" id="intelliTxt" style="padding-left: 5px; padding-right: 5px;">
Hi im looking a ways to read client MAC ID . I want to use it in a CF application.. so an ActiveX
or Javascript solution is better.. I tried to solve it using smart client ( vb.net) but it is throwing some Security excpetion.. Please help
Thanks in advance
Anz
</div>
If this post was useful to you, please mark it as answer.
var service = locator.ConnectServer();
var MACAddr ;
var IPAddr ;
var DomainAddr;
var sDNSName;
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync
(foo, 'Win32_NetworkAdapterConfiguration');
</script>
</p>
*************************
This is the second file. It is an ASP page, but you could change it to
plain HTML and use Java to retrieve the form field values, if you
wanted.
NICPost.asp
<HTML>
<HEAD>
</HEAD>
<BODY>
Network Interface Card Information Page
<BR>
<BR>
<BR>
You are at IP Address <STRONG>
<%=request.form("txtIPAddr")%>
</STRONG>
<BR>
Your MAC address on your network card is <STRONG>
<% =request.form("txtMACAddr")%>
</STRONG>
<BR>
Your DNS Host name is <STRONG>
<% =request.form("txtDNSName")%>
</STRONG>
<BR>
<BR>
<BR>
To confirm your IP and MAC address information, go to
the command prompt and
type in
<BR>
<BR>
IPCONFIG/ALL
<BR>
<BR>
ASP reports that your IP Address is <STRONG>
<%
response.Write Request.Servervariables("REMOTE_ADDR")
%>
</STRONG>which is your external WAN IP address that
anyone can see,
<BR>
but maybe be shared by hundreds of users if you use Net
Address Translation
(NAT)
<BR>
through a common router.
</BODY>
</HTML
Getting the MAC Address works for some users on the same LAN as yourself.
Click "Mark as Answer" on the post that helped you.
This earns you a point and marks your thread as Resolved so we will all know you have been helped.
FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239
But, I do not need the client machine's IP Address and i need the MAC Address.
IP can be get from the code in the link which you referred. But i need the MAC address of the machine from which we are accessing the url.
I used the server side code for getting the MAC Address from server End:
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject mo in moc)
{
if (MACAddress == String.Empty)
{
if ((bool)mo["IPEnabled"] == true)
{
MACAddress = mo["MacAddress"].ToString();
}
}
}
But it returns the Mac Address of the Server and not the client.
As to get this information from client end, i opted for the following javascript:
<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);
anzer
Star
7928 Points
1506 Posts
Client MAC address
Jan 02, 2006 07:57 AM|LINK
Hi im looking a ways to read client MAC ID . I want to use it in a CF application.. so an ActiveX
or Javascript solution is better.. I tried to solve it using smart client ( vb.net) but it is throwing some Security excpetion.. Please help
Thanks in advance
Anz
</div>
ClientSideAsp.Net | Blog
Freakyuno
Star
12518 Points
1952 Posts
Re: Client MAC address
Jan 02, 2006 12:38 PM|LINK
Try this
Copy and paste the two ASPFiles below.
The first ASP file- NIC5.ASP
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>WMI Scripting HTML</title>
<script FOR="foo" EVENT="OnCompleted(hResult,
pErrorObject, pAsyncContext)" LANGUAGE="JScript">
document.forms[0].txtMACAddr.value=unescape(MACAddr);
document.forms[0].txtIPAddr.value=unescape(IPAddr);
document.forms[0].txtDNSName.value=unescape(sDNSName);
document.formbar.submit();
</script>
<script FOR="foo" EVENT="OnObjectReady(objObject,
objAsyncContext)" LANGUAGE="JScript">
if(objObject.IPEnabled != null && objObject.IPEnabled !
= "undefined" && objObject.IPEnabled == true)
{
if(objObject.MACAddress != null &&
objObject.MACAddress != "undefined")
MACAddr = objObject.MACAddress;
if(objObject.IPEnabled && objObject.IPAddress(0) !=
null && objObject.IPAddress(0) != "undefined")
IPAddr = objObject.IPAddress(0);
if(objObject.DNSHostName != null &&
objObject.DNSHostName != "undefined")
sDNSName = objObject.DNSHostName;
}
</script>
</head>
<body>
<p>
<FONT color="red"><span
ID="info"> </span>. </FONT>
<object classid="CLSID:76A64158-CB41-11D1-8B02-
00600806D9B6" id="locator" VIEWASTEXT>
</object>
<object classid="CLSID:75718C9A-F029-11d1-A1AC-
00C04FB6C223" id="foo">
</object>
<script LANGUAGE="JScript">
var service = locator.ConnectServer();
var MACAddr ;
var IPAddr ;
var DomainAddr;
var sDNSName;
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync
(foo, 'Win32_NetworkAdapterConfiguration');
</script>
</p>
<form method="POST" action="NICPost.asp" id="formfoo" name="formbar">
<input type="hidden" name="txtMACAddr">
<input type="hidden" name="txtIPAddr">
<input type="hidden" name="txtDNSName">
</form>
</body>
</html>
*************************
This is the second file. It is an ASP page, but you could change it to
plain HTML and use Java to retrieve the form field values, if you
wanted.
NICPost.asp
<HTML>
<HEAD>
</HEAD>
<BODY>
Network Interface Card Information Page
<BR>
<BR>
<BR>
You are at IP Address <STRONG>
<%=request.form("txtIPAddr")%>
</STRONG>
<BR>
Your MAC address on your network card is <STRONG>
<% =request.form("txtMACAddr")%>
</STRONG>
<BR>
Your DNS Host name is <STRONG>
<% =request.form("txtDNSName")%>
</STRONG>
<BR>
<BR>
<BR>
To confirm your IP and MAC address information, go to
the command prompt and
type in
<BR>
<BR>
IPCONFIG/ALL
<BR>
<BR>
ASP reports that your IP Address is <STRONG>
<%
response.Write Request.Servervariables("REMOTE_ADDR")
%>
</STRONG>which is your external WAN IP address that
anyone can see,
<BR>
but maybe be shared by hundreds of users if you use Net
Address Translation
(NAT)
<BR>
through a common router.
</BODY>
</HTML
My Blog
anzer
Star
7928 Points
1506 Posts
Re: Client MAC address
Jan 03, 2006 04:02 AM|LINK
Thanks Freakyuno thanks a lot...Iits working wonderfully...
Anz
ClientSideAsp.Net | Blog
ukr
Participant
822 Points
157 Posts
Re: Client MAC address
Apr 13, 2009 09:41 AM|LINK
Hello,
I tried the above code in the IE8 and its displaying some empty values with out the MAC Address.
Can you let me know the exact html code of how to access the same?
Thnak you in Advance
Mark this as Answer if it helps you, As some other might get the solution quickly...!
TATWORTH
All-Star
72415 Points
14017 Posts
MVP
Re: Client MAC address
Apr 14, 2009 03:26 PM|LINK
Getting the MAC Address works for some users on the same LAN as yourself.
This earns you a point and marks your thread as Resolved so we will all know you have been helped.
FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Client MAC address
Apr 14, 2009 03:49 PM|LINK
You can't rely on javascript for MAC Address another solution IPAddress
http://www.aspsnippets.com/post/2009/04/11/How-to-get-IP-Address-of-Visitors-Machine-in-ASPNet.aspx
Contact me
ukr
Participant
822 Points
157 Posts
Re: Client MAC address
Apr 15, 2009 12:56 PM|LINK
Helo Khan,
Thank for your Reply...
But, I do not need the client machine's IP Address and i need the MAC Address.
IP can be get from the code in the link which you referred. But i need the MAC address of the machine from which we are accessing the url.
I used the server side code for getting the MAC Address from server End:
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject mo in moc)
{
if (MACAddress == String.Empty)
{
if ((bool)mo["IPEnabled"] == true)
{
MACAddress = mo["MacAddress"].ToString();
}
}
}
But it returns the Mac Address of the Server and not the client.
As to get this information from client end, i opted for the following javascript:
<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>
As the ActiveXObject is not available with the Firefox, its not working with the firefox and is working fine in IE.
Can any body let me know if any work around for this?
Thanks in Advance for the help...!
Mark this as Answer if it helps you, As some other might get the solution quickly...!
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Client MAC address
Apr 15, 2009 01:58 PM|LINK
Well there is no other way
and ActiveX too runs when the Security settings are lowered in IE
Contact me
prvsuresh
Member
4 Points
2 Posts
Re: Client MAC address
Feb 23, 2010 08:26 AM|LINK
client mac id
NetworkInterface[] nics = NetworkInterface
.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
IPInterfaceProperties
properties = adapter.GetIPProperties();
adapter.GetPhysicalAddress().ToString();
//strMacArray = adapter.Id;
if (i == 0)
{
strMacArray = adapter.Id;
i = i + 1;
}
}