0

Possible Duplicate:
Reliable method to get machine's MAC address in C#

I want to obtain the mac address of the system through code in the application program so i can use it to authorize at the system level ?

Community
  • 1
  • 1
cmthakur
  • 2,266
  • 4
  • 18
  • 23
  • Duplicate of http://stackoverflow.com/questions/5908926/read-mac-address-and-c and http://stackoverflow.com/questions/850650/reliable-method-to-get-machines-mac-address-in-c and http://stackoverflow.com/questions/3157246/getting-mac-address-c and so many more. – Richard Brightwell Jun 20 '11 at 09:32
  • 1
    "the" mac address? The address returned from Me Disappointment's answer might be the address of a wireless card temporarily attached to the machine just during installation. There's no 1-1 mapping between mac addresses and systems, so using it as an authorization or authentication mechanism is a very poor choice. – Damien_The_Unbeliever Jun 20 '11 at 10:10

1 Answers1

0

You can get it via the active network interface, such as:

var mac =
    (from item in NetworkInterface.GetAllInterfaces()
    where item.OperationalStatus == OperationalStatus.Up
    select item.GetPhysicalAddress()).FirstOrDefault();

Failing retrieval from an active interface, you might consider just grabbing the loopback address. Also, you could loop the elements as opposed to using Linq, should you wish to.

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129