Unfortunately there is no standard method in .Net you can call to resolve an systems MAC address. To do that you have to load the Windows IP helper API to make use of the SendARP function.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Windows.Forms;
 
 
namespace SendARPRequest
{
    class Program
    {
 
        [System.Runtime.InteropServices.DllImport("Iphlpapi.dll", EntryPoint = "SendARP")]
        internal extern static Int32 SendArp(Int32 destIpAddress, Int32 srcIpAddress, 
                     byte[] macAddress, ref Int32 macAddressLength);
 
 
 
        /*
         * 
         * 
         */
        static void Main(string[] pArgs)
        {
            Console.Clear();
 
            if (pArgs.Length != 1)
            {
                Console.WriteLine("Usage : {0} IP-Address", Application.ProductName);
                return;
            }
 
 
            try
            {
                String lClientMAC = GetMACFromNetworkComputer(IPAddress.Parse(pArgs[0]));
                Console.WriteLine("Client system with IP {0} has MAC {1}", pArgs[0], lClientMAC);
            }
            catch (Exception lEx)
            {
                Console.WriteLine("Error occurred : {0}", lEx.Message);
            }
 
        }
 
 
 
        /*
         * 
         * 
         */
        private static String GetMACFromNetworkComputer(IPAddress pIPAddress)
        {
            String lRetVal = String.Empty;
            Int32 lConvertedIPAddr = 0;
            byte[] lMACArray;
            int lByteArrayLen = 0;
            int lARPReply = 0;
 
            if (pIPAddress.AddressFamily != AddressFamily.InterNetwork)
                throw new ArgumentException("The remote system only supports IPv4 addresses");
 
            lConvertedIPAddr = ConvertIPToInt32(pIPAddress);
            lMACArray = new byte[6]; // 48 bit
            lByteArrayLen = lMACArray.Length;
 
            if ((lARPReply = SendArp(lConvertedIPAddr, 0, lMACArray, ref lByteArrayLen)) != 0)
                throw new Exception(String.Format("Error no. {0} occured while resolving MAC " +
                                                  " address of system {1}", lARPReply,
                                                  pIPAddress.ToString()));
 
 
            //return the MAC address in a PhysicalAddress format
            for (int i = 0; i < lMACArray.Length; i++)
            {
                lRetVal += String.Format("{0}", lMACArray[i].ToString("X2"));
                lRetVal += (i != lMACArray.Length - 1) ? "-" : "";
            } // for (in...
 
            return (lRetVal);
        }
 
 
        /*
         * 
         * 
         */
        private static Int32 ConvertIPToInt32(IPAddress pIPAddr)
        {
            byte[] lByteAddress = pIPAddr.GetAddressBytes();
            return BitConverter.ToInt32(lByteAddress, 0);
        }
 
    }
}