Click here to Skip to main content
15,791,252 members
Please Sign up or sign in to vote.
1.40/5 (3 votes)
See more:
hi frnds

i need MAC Address of client machine using
Updated 4-May-20 10:02am
Sandeep Mewara 26-Apr-11 9:29am    
"I need".... do you even try anything by yourself?

namespace: using System.Management;
string id=" ";
ManagementObjectSearcher query = null;
ManagementObjectCollection queryCollection = null;

               query = new ManagementObjectSearcher("SELECT * FROM                                  Win32_NetworkAdapterConfiguration");
            queryCollection = query.Get();
            foreach (ManagementObject mo in queryCollection)
              if (mo["MacAddress"] != null)
                 id = mo["MacAddress"].ToString();
      catch (Exception ex)
Share this answer
amitthakkar1987 26-Apr-11 7:45am    
it will give server MAC Address ... i need client MAC Address
ambarishtv 26-Apr-11 7:56am    
var strComputer = ".";
var objWMIService = GetObject("winmgmts:\\\\" + strComputer + "\\root\\cimv2");
var e = new Enumerator(objWMIService.ExecQuery("Select * from Win32_NetworkAdapter","WQL",48));

for (;!e.atEnd();e.moveNext())
{ objItem = e.item();
WScript.Echo ("MACAddress: " + objItem.MACAddress)
Member 9518177 21-Apr-19 9:37am    
no t working
GetMacAdress method without using System.Management

private string GetMAC()
            string macAddresses = "";

            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
                if (nic.OperationalStatus == OperationalStatus.Up)
                    macAddresses += nic.GetPhysicalAddress().ToString();
            return macAddresses;
Share this answer
Michal Rezler 7-Feb-13 8:22am    
Geat works. Many thanks
protected void Page_Load(object sender, EventArgs e)
          string macid= GetMacAddress("pass IP Address of the mechine");
       [DllImport("iphlpapi.dll", ExactSpelling = true)]
       public static extern int SendARP(int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen);
       public string GetMacAddress(string sName)
           string s = string.Empty;
           System.Net.IPHostEntry Tempaddr = null;
           Tempaddr = (System.Net.IPHostEntry)Dns.GetHostEntry(sName);
           System.Net.IPAddress[] TempAd = Tempaddr.AddressList;
           string[] Ipaddr = new string[3];
           foreach (IPAddress TempA in TempAd)
               Ipaddr[1] = TempA.ToString();
               byte[] ab = new byte[6];
               int len = ab.Length;
               int r = SendARP((int)TempA.Address, 0, ab, ref len);
               string sMAC = BitConverter.ToString(ab, 0, 6);
               Ipaddr[2] = sMAC;
               s = sMAC;
           return s;
Share this answer
anvas kuttan 26-Apr-11 8:02am    
this will help i am sure just copy paste the code
hadi5526 24-Jul-12 4:49am    
very good .before use this code add
using System.Net;
using System.Runtime.InteropServices;
vgsonekar19 12-Mar-13 9:15am    
not working
Member 12282638 27-Jan-16 14:22pm    
where is dll for this
public string GetMACAddress()
ManagementObjectSearcher objMOS = new ManagementObjectSearcher("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMOS.Get();
string MACAddress = String.Empty;
foreach (ManagementObject objMO in objMOC)
if (MACAddress == String.Empty) // only return MAC Address from first card
MACAddress = objMO["MacAddress"].ToString();
MACAddress = MACAddress.Replace(":", "");
return MACAddress;
Share this answer
CHill60 9-Aug-13 8:07am    
You do realise this question was over 2 years old with 3 solutions already posted?

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