Curiosità

Chi sa perchè appena esce un nuovo linguaggio o appena uno decide di impararne uno, le prime domande postate sui forum sono tutte del tipo : "come faccio a leggere il numero seriale del mio harddisk?" ??

Qualcuno ha una risposta ?

p.s: quando io mi sono affacciato per la prima volta all'assembler, la mia prima domanda su una bbs è stata su come creare programmini TSR... andavo alla folle velocità di 1200 =)

powered by IMHO

posted @ lunedì 17 gennaio 2005 19.22

Print

Comments on this entry:

# re: Curiosità;

Left by Anonymous at 17/01/2005 20.08
Gravatar
...probabilmente si cerca di tutelare il proprio lavoro ! si cerca di evitare la diffusione non autorizzata

# re: Curiosità

Left by Matteo G.P. Flora at 18/01/2005 12.31
Gravatar
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);
}

}
}

Your comment:



 (will not be displayed)


 
 
 
Please add 3 and 6 and type the answer here:
 

Live Comment Preview:

 
«febbraio»
domlunmarmergiovensab
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910