Dan,
Try the following code.
protected string GetMACAddressByIP(string ip)
{
try
{
System.Management.ManagementObjectSearcher query= new
System.Management.ManagementObjectSearcher("SELECT * FROM
Win32_NetworkAdapterConfiguration");
System.Management.ManagementObjectCollection queryCollection =
query.Get();
bool Found = false;
foreach(System.Management.ManagementObject mo in queryCollection)
{
if(mo["IPAddress"] != null)
{
string temp;
temp = string.Join(".",(string[])mo["IPAddress"] );
if(!temp.Equals(""))
{
if(!ip.Equals(""))
{
if(temp.Equals(ip.Trim()))
{
Found = true;
}
}
else
{
Found = true;
}
}
if(Found == true)
{
if(mo["macaddress"] != null)
{
if(!mo["macaddress"].Equals(""))
{
return (string)mo["macaddress"];
}
}
}
else
{
Found = false;
}
}
}
MessageBox.Show("No Mac Address Found");
return "";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return "";
}
}
Regards
Scott Blood
C# Developer
"Dan" <ds**@NOSPAMyork.ac.uk> wrote in message
news:uj**************@TK2MSFTNGP14.phx.gbl...
Hi
Does anyone know how to get the Mac address of a remote PC, using C#? I
believe it's possible by deconstructing the packet received from a ping
but I don't know how to do it.
TIA
Dan