Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I search it on google but i can't get perfect code. i try some codes but i am not able track the client mac address i am getting server mac adress. in local its works fine but when i upload on server i am not getting mac adress of my machine.

here some code i am using

using System.Net.NetworkInformation;

C#
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
              Label1.Text = nics[0].GetPhysicalAddress().ToString();


if other solution please provide me..
Posted
Comments
Sergey Alexandrovich Kryukov 16-Jul-14 3:19am    
Why? why?!
—SA

Web applications don't have access to client systems. And this is very good. If some sites could detect your MAC address, would you ever trust them?

—SA
 
Share this answer
 
Comments
utm 16-Jul-14 3:26am    
for some security purpose..
i have requirement for attendence can be done from only single pc..
so that person can't give attendece from home..
Sergey Alexandrovich Kryukov 16-Jul-14 9:39am    
Are serious? Security through MAC address? I already told you why it cannot work. You need to explain your ultimate goal, in detail, only then you can get some practical advice.
—SA
check this previous question and answers: how to get client mac address[^]
 
Share this answer
 
Comments
utm 16-Jul-14 3:32am    
thanks for reply but not getting Answer..
You need to import the System.Net namespace in your code for this to work. This will support IPv4 and IPv6.

public string GetMACAddress()
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
String sMacAddress = string.Empty;
foreach (NetworkInterface adapter in nics)
{
if (sMacAddress == String.Empty)// only return MAC Address from first card
{
IPInterfaceProperties properties = adapter.GetIPProperties();
sMacAddress = adapter.GetPhysicalAddress().ToString();
}
} return sMacAddress;
}















XML
To get the client MAC address only way we can rely on JavaScript and Active X control of Microsoft.It is only work in IE if Active X enable for IE. As the ActiveXObject is not available with the Firefox, its not working with the firefox and is working fine in IE.

This script is for IE only:

<script language="javascript" type="text/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>
 
Share this answer
 
Comments
utm 16-Jul-14 4:31am    
above c# code work as mine..after upload it give me the server mac address

javascript code not working in my local machine...still trying

thanks for reply..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900