-3

I'm using C# on my project and I want to run only on selected Computers, we've used mac-address to check if computers mac-address are in the list and if not message show like.

enter image description here

how to do this using C#?

if (listofmacaddress == true)
{
     //run the program
}
else
{
     MessageBox.Show("Invalid mac address, application close. ",
                     "Error",
                      MessageBoxButtons.OK, 
                      MessageBoxIcon.Error);
}

public static bool listofmacaddress()
{
    var mac = // get mac address
    if(mac == "##########1")
       return true;
    else if(mac == "#########2")
       return true;
    else
       return false;
}
Ramgy Borja
  • 2,330
  • 2
  • 19
  • 40
  • https://stackoverflow.com/questions/850650/reliable-method-to-get-machines-mac-address-in-c-sharp – Evan Weissburg Sep 09 '17 at 01:51
  • 1
    it must be a function that check if pc macaddress is in the list, if mac address found return true else false something like that. – Ramgy Borja Sep 09 '17 at 01:54
  • 1
    @KenWhite no its not. – Ramgy Borja Sep 09 '17 at 02:01
  • 2
    Yes, it is; I can read. The question you asked is distilled to one line of your code, which is `var mac = // get mac address`, which that question answers. If you have a different question, then ask that different question instead. – Ken White Sep 09 '17 at 02:02
  • 2
    The stated goal seems silly. This will run in machines that have a NIC with the specific MAC address, so just move the NIC around to the machine you want to run the program in, or create a virtual machine and set the MAC to a known value, which can be retrieved from the binary using the `strings` command in Linux. – code_dredd Sep 09 '17 at 02:05
  • I've rolled back your edit. Adding a new requirement which totally changes the question is wrong. It invalidates answers you've already received. Your original question didn't ask about anything but MAC addresses. In addition, there are existing questions about uniquely identifying computer hardware, which you clearly haven't bothered searching for any more than you did the question about MAC addresses. Do your own searching and research instead of expecting us to do it for you. – Ken White Sep 09 '17 at 02:08
  • And a point (which you will find when you search for all those existing questions I mentioned): What happens when the user has to replace a piece of hardware or buys a new computer, and the app they paid for no longer executes? Depending on hardware for licensing is a ludicrous idea - implement a proper licensing methodology and quit wasting your time on a strategy that has been proven wrong for a decade now. – Ken White Sep 09 '17 at 02:16
  • @KenWhite ok sir appreciate, sir my new question how to check disk serial number, thanks in advance. – Ramgy Borja Sep 09 '17 at 02:19
  • That's not part of **this** question, which is about MAC addresses, to which you've already received an answer. I explained that when I rolled back your edit. Read my last two comments. Do the searching I also mentioned in those comments. – Ken White Sep 09 '17 at 02:21
  • @KenWhite all i want is to run only a program to selected computers so that if ever they will copy the program, it will not run on their computer. – Ramgy Borja Sep 09 '17 at 02:22
  • 1
    Again, **read my last comments**, which specifically address the questions that are already here about that exact topic. Are you reading anything I'm writing? **The idea of using hardware identification does not work. Hardware has to be replaced or can be spoofed. This has been discussed here in dozens of questions before. Do some searching for uniquely identifying hardware to see why it's a bad idea. Do NOT expect us to do that searching here for you.** And **this question** is about identifying the MAC address, and it is a **duplicate** of the post I linked. – Ken White Sep 09 '17 at 02:24
  • 1
    For additional reference, see the accepted answer to [this Meta post](https://meta.stackoverflow.com/q/290746/62576) about changing question requirements or asking additional questions after your original question has been answered. – Ken White Sep 09 '17 at 02:32

1 Answers1

0

Something like this:

public string GetMACAddress()
{
    NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
    string macAddress = string.Empty;
    foreach (NetworkInterface adapter in nics)
    {
        if (macAddress == String.Empty)
        {
            var properties = adapter.GetIPProperties();
            macAddress = adapter.GetPhysicalAddress().ToString();
        }
    } return macAddress;
}
Mr Slim
  • 1,458
  • 3
  • 17
  • 28