The following code returns an 8 digit number that is the 'fingerprint' of the hardware of the PC it is running on.
Note that this is C# code and will not run on VB. Will probably adapt to VB.NET ok (any volunteers?)
Call with something like:
You can play around with what you test. This example tests quiteCode:Fingerprint fp = new Fingerprint(); MessageBox.Show(fp.Value());
a few things and might be too slow for some uses - but testing
fewer things is less secure.
Note that not all PC's have all items. e.g. may not have network
card. Will not hang in this case as returns default values. Older
PC's may not have things like unique CPU or motherboard serial
numbers, so don't rely on this.
Normal use for this type of application is to generate 'activation'
codes for software. Customer sends you his fingerprint and you
send him a matching code to activate the software. If he posts
the code on the Internet, you don't need to worry too much as it
will only run on machines with the same fingerprint.
Advantages: more secure than universally reuseable activation
code, which will soon be on the serialz sites. Cheaper than a
dongle and nothing to ship.
Disadvantage: If legit user changes hardware then needs a new
code. May disuade/irritate some purchasers. (Best used with a
website where users can generate their own reactivation codes
to be sent only to their registered email address - and kill that
address if it generates an unreasonable number requests on the
same serial number. If app is guaranteed Internet access - e.g.
it's a browser or an FTP tool - then this process can be invisible to
the customer - just do it in background.)
Code:using System; using System.Globalization; using System.Threading; using System.Resources; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Reflection; using System.Text; namespace Whatever { public class Fingerprint //Fingerprints the hardware { public string Value() { return pack(cpuId() + biosId() + diskId() + baseId() + videoId() + macId()); } private string identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue) //Return a hardware identifier { string result=""; System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass); System.Management.ManagementObjectCollection moc = mc.GetInstances(); foreach(System.Management.ManagementObject mo in moc) { if(mo[wmiMustBeTrue].ToString()=="True") { //Only get the first one if (result=="") { try { result = mo[wmiProperty].ToString(); break; } catch { } } } } return result; } private string identifier(string wmiClass, string wmiProperty) //Return a hardware identifier { string result=""; System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass); System.Management.ManagementObjectCollection moc = mc.GetInstances(); foreach(System.Management.ManagementObject mo in moc) { //Only get the first one if (result=="") { try { result = mo[wmiProperty].ToString(); break; } catch { } } } return result; } private string cpuId() { //Uses first CPU identifier available in order of preference //Don't get all identifiers, as very time consuming string retVal = identifier("Win32_Processor","UniqueId"); if (retVal=="") //If no UniqueID, use ProcessorID { retVal = identifier("Win32_Processor","ProcessorId"); if (retVal=="") //If no ProcessorId, use Name { retVal = identifier("Win32_Processor","Name"); if (retVal=="") //If no Name, use Manufacturer { retVal = identifier("Win32_Processor","Manufacturer"); } //Add clock speed for extra security retVal +=identifier("Win32_Processor","MaxClockSpeed"); } } return retVal; } private string biosId() //BIOS Identifier { return identifier("Win32_BIOS","Manufacturer") + identifier("Win32_BIOS","SMBIOSBIOSVersion") + identifier("Win32_BIOS","IdentificationCode") + identifier("Win32_BIOS","SerialNumber") + identifier("Win32_BIOS","ReleaseDate") + identifier("Win32_BIOS","Version"); } private string diskId() //Main physical hard drive ID { return identifier("Win32_DiskDrive","Model") + identifier("Win32_DiskDrive","Manufacturer") + identifier("Win32_DiskDrive","Signature") + identifier("Win32_DiskDrive","TotalHeads"); } private string baseId() //Motherboard ID { return identifier("Win32_BaseBoard","Model") + identifier("Win32_BaseBoard","Manufacturer") + identifier("Win32_BaseBoard","Name") + identifier("Win32_BaseBoard","SerialNumber"); } private string videoId() //Primary video controller ID { return identifier("Win32_VideoController","DriverVersion") + identifier("Win32_VideoController","Name"); } private string macId() //First enabled network card ID { return identifier("Win32_NetworkAdapterConfiguration","MACAddress", "IPEnabled"); } private string pack(string text) //Packs the string to 8 digits { string retVal; int x = 0; int y = 0; foreach(char n in text) { y ++; x += (n*y); } retVal = x.ToString() + "00000000"; return retVal.Substring(0,8); } } }




Reply With Quote