none
How to Access the Mac Address of client system RRS feed

  • Question

  • How to access the MAC address of the system?
     
    I have a code which is working fine but only on localhost. After publishing my website on server, it cannot access the MAC Address and either throw an exception object reference not set to an instance of an object  or after using try catch it move to catch block.
     
    I am providing my code, so that anyone can suggest me something fruitful:
     
    public string GetMACAddress()
    {
    try
    {
    ManagementClass objMOS = new ManagementClass("Win32_NetworkAdapterConfiguration");
    ManagementObjectCollection objMOC = objMOS.GetInstances();
    string MACAddress = String.Empty;
    foreach (ManagementObject objMO in objMOC)
    {
    if (MACAddress == String.Empty) // only return MAC Address from first card
    {
    MACAddress = objMO["MacAddress"].ToString();
    }
    objMO.Dispose();
    }
    MACAddress = MACAddress.Replace(":", "");
    return MACAddress;
    }
    catch (Exception ei)
    {
    return "No Mac";
    }
    }
      

    I am developing an ecommerce site where i need to provide a service of add to cart    
    without login into website, for which i use mac address as a unique identity for every customer.
    So please guide me for this same work.

    Thursday, September 17, 2015 3:02 PM

Answers

All replies

  • This is not meant as offence:

    This is completely nonsense.

    The MAC you see is only the MAC of the last device or router in the chain between your server and the client.

    You may ask: Why?

    Networking Basics! The MAC is only useful in a local network for delivering packets. For nothing else. And it's only necessary that the MAC is unique in this domain. It's not a global unique id.

    A packet from your client reaches a router. Then it is routed, this means it is now in a different network, and it now contains the MAC of the router. And so on for each hop.

    It is absolutely not useable for identification. Especially as MACs are not unique. They should be, but they aren't, cause some vendors haven't take much care. Then on some systems you may enter the MAC manually and can reuse it.

    Further more, you're returning the first MAC. There is absolutely no guarantee, that the next time I haven't plugged in a further NIC. And now the order is different.

    This entire idea is absolutely whacky.

    Use cookies or an identity provider..


    Thursday, September 17, 2015 3:15 PM
  • Thank you for reply, can you guide me any method to create unique identity between each system.
    Thursday, September 17, 2015 3:45 PM
  • What's wrong with cookies?

    Thursday, September 17, 2015 4:11 PM
  • Probably as sensible as having this discussion in a developer forum, not Microsoft Project Online.

    Gary Chefetz, MCITP, MCP, MVP msProjectExperts
    Project and Project ServerFAQs
    Project Server Help BLOG

    Tuesday, September 22, 2015 1:18 PM
    Moderator