Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
C#
In my project, we need to find out User MAC Address and IP Address kindly Provide the sample code (using C# Code behind or JavaScript or ActiveX controls). Thanks in Advance
Posted
Comments
Sergey Alexandrovich Kryukov 3-Feb-16 0:14am    
Why?

In principle, it is possible just for some kind of browsers (guess which kind :-), but most security-savvy users will have to blacklist your whole site for doing such dirty tricks. However, such users usually avoid using such browsers. I can see you "ActiveX" tag — it really tells the tail.

—SA
Manivannan.k88 3-Feb-16 4:19am    
Sir,
In activeX control working, only user need to manually enabling this option(Security->Internet->Custom level Initialize and script ActiveX controls not marked as safe for scripting - >Enable(not secure) ). We can’t guide all user to enable this option. So i need alternative solution for to get MAC Address.
Sergey Alexandrovich Kryukov 3-Feb-16 9:30am    
Why?
—SA
Beginner Luck 3-Feb-16 0:47am    
which javascript or C# u wan to use to get User MAC Address and IP Address
Manivannan.k88 3-Feb-16 4:24am    
sir,
i need sample code to get the user MAC address

1 solution

javascript


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;
    } 


C#

using system.net
using System.Net.NetworkInformation

IPAddressInformation Class (System.Net.NetworkInformation)[^]


PhysicalAddress Class (System.Net.NetworkInformation)[^] is for mac address
 
Share this answer
 
v2

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