473,469 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

getting a mac address

Dan
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
Mar 23 '06 #1
3 15711
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

Mar 23 '06 #2
Scott's code looks promising...

But keep in mind that you will only be able to get the MAC address of
computers on the local network since that code looks like it's using the ARP
cache on the local machine or where ever the code is running.

As an example, you can not get the MAC address of a computer if you have to
go through a router.

If you're looking to get a MAC address of Windows PCs and you have the
username and password, you can check out the getmac command in the command
prompt. This command will be able to get the MAC address of computers across
routers since it doesn't use the ARP cache. It probably does a remote
procedure call to the Windows PC.

-Pat
Mar 23 '06 #3
Not at all, the code as is gets the MAC address of the local NIC's that are
IP enabled, but you can modify the code to query a remote
server/workstation, all you need are appropriate permissions to access the
remote system (just as getmac needs it).

Willy.

"pkaeowic" <pk******@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
| Scott's code looks promising...
|
| But keep in mind that you will only be able to get the MAC address of
| computers on the local network since that code looks like it's using the
ARP
| cache on the local machine or where ever the code is running.
|
| As an example, you can not get the MAC address of a computer if you have
to
| go through a router.
|
| If you're looking to get a MAC address of Windows PCs and you have the
| username and password, you can check out the getmac command in the command
| prompt. This command will be able to get the MAC address of computers
across
| routers since it doesn't use the ARP cache. It probably does a remote
| procedure call to the Windows PC.
|
| -Pat
Mar 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Spidah | last post by:
How do I get the contents of the browser address bar with PHP - assuming it is possible? In javascript it is done with: unescape(window.location.pathname), but is there a php equivalent? ...
9
by: Marchello | last post by:
Hi All. I will try to explain my question on following example: Having class CInteger (wraper on 'int' values): class CInteger { public: ..... void SetValueFromPoiner(int *new_value)
3
by: Fred Zwarts | last post by:
For some operations, e.g., if one needs to write a large vector of floats to a file, the address of a buffer is needed. Does the vector class is the STL offer a way to get access to its internal...
8
by: Timo | last post by:
I am trying to get address of myStruct to a string array texts. I am using M$ Visual C++ 6.0 (this is not OS specific question, though, this code should also work on 16 bit embedded compiler ;)). ...
7
by: Prashanth Badabagni | last post by:
#include<string.h> void (*foobar)(); void main() { char *str; strcpy(str,"Fun1"); strcat(str,"method1");
5
by: sujit1779 | last post by:
Hi, How can i get the address opened by a user in his internet explorer or any other browser. For eg if a user has opened site www.yahoo.com then, how can I get that programatically thanks
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.