Get Mac address

A

adenyer

Hi

I need to get a unique identifier to a machine, I chose to use a MAC
address. The problem I am having is that the methods I have found on
the internet and through Google groups aren't sufficient for what I
require.

Option 1 - using WMI
Unfortunately I'm using Framework 1.1
http://groups.google.co.uk/group/mi...p/browse_thread/thread/df2e6e2a3183a4dd?hl=en

Option 2 - Using Send ARP
The machine isn't always connected to a network so it doesn't always
have an IP address, no IP no ARP packets.

Any help would be much appreciated.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


what is wrong with WMI ? it does work in 1.1 , use this code:

ManagementClass mc = new ManagementClass("Win32_NetworkAdapter");
foreach (ManagementObject mo in mc.GetInstances())
{
string macAddr = mo["MACAddress"] as string;
if ( macAddr != null && macAddr.Trim() != "" )
return macAddr.ToString();
}


Note that it does not work in win9X
 
A

adenyer

Windows Management Instrumentation ....

using System.Management;

...

ManagementClass mc = new ManagementClass("Win32_NetworkAdapter");

I had some trouble getting that code to work .....

error CS0234: The type or namespace name 'Management' does not exist in
the class or namespace 'System' (are you missing an assembly
reference?)
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Windows Management Instrumentation ....

using System.Management;

..

ManagementClass mc = new ManagementClass("Win32_NetworkAdapter");

I had some trouble getting that code to work .....

error CS0234: The type or namespace name 'Management' does not exist in
the class or namespace 'System' (are you missing an assembly
reference?)

You have to include a reference to System.Management in "Add reference"
form the project menu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top