简体   繁体   中英

How to make installation package of a desktop application with MAC address restriction?

I have created an inventory system in c#. Now I want to make its installation package so it can be installed on other computers.

I know how to make an installation package but the problem is that I want to restrict the application from being installed on an other computer by checking the MAC address of the computer. How can i check the MAC address of the computer during installation and compare it with the MAC address which I have given?

Also I want to know that how can I integrate database with installation package so that I should not integrate it separately.

You may use PhysicalAddress class ( http://msdn.microsoft.com/en-us/library/system.net.networkinformation.physicaladdress%28v=vs.110%29.aspx ):

NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            //for each j you can get the MAC
            PhysicalAddress address = nics[j].GetPhysicalAddress();
            byte[] bytes = address.GetAddressBytes();
            for (int i = 0; i < bytes.Length; i++)
            {
                // Display the physical address in hexadecimal.
                Console.Write("{0}", bytes[i].ToString("X2"));
                // Insert a hyphen after each byte, unless we are at the end of the
                // address.
                if (i != bytes.Length - 1)
                {
                    Console.Write("-");
                }
            }

You could store this value into DB and verify (when installing) if this MAC Address was already used.

Be aware that is possible to clone MAC Address. So, I would use another way to secure my application.

***** UPDATE *****

There are a lot of differents ways to reach machine uniqueness. So I would start by hashing HDD info like this: http://www.vcskicks.com/hardware_id.php .

ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + drive + @":""");
dsk.Get();
string volumeSerial = dsk["VolumeSerialNumber"].ToString();

You could also get more information together and generate a hash. Here is an example: http://www.codeproject.com/Articles/28678/Generating-Unique-Key-Finger-Print-for-a-Computer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM