-2

I need to get a unique ID from a computer using c#. I have done it with Mac Address by using the code

string macAddresses = "";
           foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
           {
               if (nic.OperationalStatus == OperationalStatus.Up)
               {
                   macAddresses += nic.GetPhysicalAddress().ToString();
                   break;
               }
           }
           return macAddresses;

But when I run code in server , it returns Mac address of the server. How can I get the Mac address or any unique ID of the client system using c#.

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107

2 Answers2

2

There is nothing like a unique ID that is automatically sent to the server with requests.

One way to implement this is to generate a unique ID on the server for each time a new client connects and send this ID to the client so that it can send it with each subsequent request and you can identify it by this ID.

Of course you have to make sure that the ID you generate is actually unique and you have to store the generated IDs on the server to know about existing "connections" and to be able to reject fake IDs.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
0

As Martin said:

There is nothing like a unique ID that is automatically sent to the server with requests.

.

You need to get that information passed INSIDE your request to be able to process it in the C# code.

For security reasons, by default of all modern broswers, you can't access the client's MAC address via JS. See more

(ASP.Net) You could set up a Session GUID as a cookie at the first time the client access your website, that should be enought to identify the users.

(WinForms/WPF) You can use that same code at the CLIENT application, then send it to your api/webservice.

(WinForms/WPF) There is also something called HD UUID (Maybe Windows-only), which can be modified by third-party softwares, which makes it not 100% safe (I've seen people modifying this to "fake auth" some licensed softwares). See more

Also could be useful if you specify what kind of server is this, I'm assuming it is web, but got some WinForms/WPF alternatives

Bruno Miquelin
  • 651
  • 1
  • 8
  • 22