천객만래 [千客萬來] (It has an interminable succession of visitors)

하드웨어 유일키 생성



using System;
using System.Management;
using System.Security.Cryptography;
using System.Security;
using System.Collections;
using System.Text;
namespace Security
{
    /// <summary>
    /// Generates a 16 byte Unique Identification code of a computer
    /// Example: 4876-8DB5-EE85-69D3-FE52-8CF7-395D-2EA9
    /// </summary>
    public class FingerPrint  
    {
        private static string fingerPrint = string.Empty;
        public static string Value()
        {
            if (string.IsNullOrEmpty(fingerPrint))
            {
                fingerPrint = GetHash("CPU >> " + cpuId() + "\nBIOS >> " + 
   biosId() + "\nBASE >> " + baseId()
                            //+"\nDISK >> "+ diskId() + "\nVIDEO >> " + 
   videoId() +"\nMAC >> "+ macId()
                                     );
            }
            return fingerPrint;
        }
        private static string GetHash(string s)
        {
            MD5 sec = new MD5CryptoServiceProvider();
            ASCIIEncoding enc = new ASCIIEncoding();
            byte[] bt = enc.GetBytes(s);
            return GetHexString(sec.ComputeHash(bt));
        }
        private static string GetHexString(byte[] bt)
        {
            string s = string.Empty;
            for (int i = 0; i < bt.Length; i++)
            {
                byte b = bt[i];
                int n, n1, n2;
                n = (int)b;
                n1 = n & 15;
                n2 = (n >> 4) & 15;
                if (n2 > 9)
                    s += ((char)(n2 - 10 + (int)'A')).ToString();
                else
                    s += n2.ToString();
                if (n1 > 9)
                    s += ((char)(n1 - 10 + (int)'A')).ToString();
                else
                    s += n1.ToString();
                if ((i + 1) != bt.Length && (i + 1) % 2 == 0) s += "-";
            }
            return s;
        }
        #region Original Device ID Getting Code
        //Return a hardware identifier
        private static string identifier
  (string wmiClass, string wmiProperty, string wmiMustBeTrue)
        {
            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;
        }
        //Return a hardware identifier
        private static string identifier(string wmiClass, string wmiProperty)
        {
            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 static string cpuId()
        {
            //Uses first CPU identifier available in order of preference
            //Don't get all identifiers, as it is 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;
        }
        //BIOS Identifier
        private static string biosId()
        {
            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");
        }
        //Main physical hard drive ID
        private static string diskId()
        {
            return identifier("Win32_DiskDrive", "Model")
            + identifier("Win32_DiskDrive", "Manufacturer")
            + identifier("Win32_DiskDrive", "Signature")
            + identifier("Win32_DiskDrive", "TotalHeads");
        }
        //Motherboard ID
        private static string baseId()
        {
            return identifier("Win32_BaseBoard", "Model")
            + identifier("Win32_BaseBoard", "Manufacturer")
            + identifier("Win32_BaseBoard", "Name")
            + identifier("Win32_BaseBoard", "SerialNumber");
        }
        //Primary video controller ID
        private static string videoId()
        {
            return identifier("Win32_VideoController", "DriverVersion")
            + identifier("Win32_VideoController", "Name");
        }
        //First enabled network card ID
        private static string macId()
        {
            return identifier("Win32_NetworkAdapterConfiguration", 
    "MACAddress", "IPEnabled");
        }
        #endregion
    }
}

 

 

========================================

결과물


 

CPU >> BFEBFBFF000006FB
BIOS >> Phoenix Technologies, LTD6.00 PGOEM20070919000000.000000+000IntelR - 42302e31
BASE >> Biostar Group기반 보드 
DISK >> ST3320620AS(표준 디스크 드라이브)3720011194255
MAC >> 00:E0:4D:51:45:1C

 

 

 

CPU >> BFEBFBFF000006FB
BIOS >> Phoenix Technologies, LTD6.00 PGOEM20070919000000.000000+000IntelR - 42302e31
BASE >> Biostar Group기반 보드 
암호화 : 129D-6375-4122-54E7-D304-D826-D1E8-684C



Posted by SB패밀리




Contacting a Registration Server to obtain a unique registration key based on unique machine ID

 

Introduction
Sometimes in the industry, it is required to collect some unique machine information and send it to a server for the purpose of creating a unique registration key based on the hardware information. This is required in the case when the software requires a per PC registration. Thus we can collect the machine information of the PC in which the software was installed, and issue a registration key which will be valid only for that machine.

Background 
Using WMI functionality, it is possible to collect machine specific hardware information. 
In .NET, one can use System.Management.ManagementClass for this purpose. (This is explained in this article.)

The problem arises when we try to send this information to the server. Because of the firewall that is present in OSes starting from WinXP, if we try to send data from our application to an external server, the firewall pops up a warning to the user informing her/him that the application is trying to send data and asks the user whether she/he wants to proceed or block the application. (Also this approach will fail if the local network is connected to the Internet through a firewall, which is configured to block anything other than HTTP traffic.)

The solution thus comes in the form of HTTP (i.e. we have to send the data through HTTP).
In .NET, this is easily achieved through System.Net.WebRequest or by using a Web Service. This article uses the WebRequest approach.

Using the Code 
In the class ContactRegistationServer (UserRegistration project), you will notice that we are creating a WebRequest and passing the hardware information through QueryString.

WebResponse registrationKey = null;
String url_string = "http://localhost/Registration/Registration.aspx"
    + "?CPU=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.cpuID)
    + "&BIOS=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.biosID)
    + "&MB=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.baseID)
    + "&DISK=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.diskID)
    + "&MAC=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.macID)
    + "&VIDEO=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.videoID);
try
{
    WebRequest requestRegistration = WebRequest.Create(url_string);
    registrationKey = requestRegistration.GetResponse();
}
catch (Exception ex)
{
    System.Windows.Forms.MessageBox.Show("Failed connecting to server");
    return;
}
On the server (Refer project 'TestPage' Registration.aspx.cs), the QueryString received from the client is retrieved and a unique registration key is produced and returned to the user.

//Call the Foolproof Registration Key algorithm :)
TheFoolProofRegistrationKey regKey = new TheFoolProofRegistrationKey();
String key = regKey.getRegistrationKey(Request.QueryString["CPU"]);
Response.Write(key);
Notes: If You Decide to Download and Run the Program
If you decide to download and try the application, please make sure to create a virtual folder of the name "Registration" on your local Web server. This is required as the WebRequest is using the following URL: http://localhost/Registration/Registration.aspx (or else copy the files to a folder by the name Registration under the server root folder).

Just for the use of a novice, I have attached a few screen shots on how to add the virtual directory on IIS.


And finally you should have something as follows:

Points of Interest 
For testing purposes, I also tried to connect to the server from a different PC: (e.g.: http://10.10.42.135/Registration/Registration.aspx) and it still worked - the firewall did not complain:). 
I did not try to connect to a server outside our network, but I guess that should also work...

 

To collect machine specific information, use the code in this article.









Posted by SB패밀리












Contacting a Registration Server to obtain a unique registration key based on unique machine ID

 

Introduction
Sometimes in the industry, it is required to collect some unique machine information and send it to a server for the purpose of creating a unique registration key based on the hardware information. This is required in the case when the software requires a per PC registration. Thus we can collect the machine information of the PC in which the software was installed, and issue a registration key which will be valid only for that machine.

Background
Using WMI functionality, it is possible to collect machine specific hardware information.
In .NET, one can use System.Management.ManagementClass for this purpose. (This is explained in this article.)

The problem arises when we try to send this information to the server. Because of the firewall that is present in OSes starting from WinXP, if we try to send data from our application to an external server, the firewall pops up a warning to the user informing her/him that the application is trying to send data and asks the user whether she/he wants to proceed or block the application. (Also this approach will fail if the local network is connected to the Internet through a firewall, which is configured to block anything other than HTTP traffic.)

The solution thus comes in the form of HTTP (i.e. we have to send the data through HTTP).
In .NET, this is easily achieved through System.Net.WebRequest or by using a Web Service. This article uses the WebRequest approach.

Using the Code
In the class ContactRegistationServer (UserRegistration project), you will notice that we are creating a WebRequest and passing the hardware information through QueryString.

WebResponse registrationKey = null;
String url_string = "http://localhost/Registration/Registration.aspx"
    + "?CPU=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.cpuID)
    + "&BIOS=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.biosID)
    + "&MB=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.baseID)
    + "&DISK=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.diskID)
    + "&MAC=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.macID)
    + "&VIDEO=" + System.Web.HttpUtility.UrlEncode(hardwareInfo.videoID);
try
{
    WebRequest requestRegistration = WebRequest.Create(url_string);
    registrationKey = requestRegistration.GetResponse();
}
catch (Exception ex)
{
    System.Windows.Forms.MessageBox.Show("Failed connecting to server");
    return;
}
On the server (Refer project 'TestPage' Registration.aspx.cs), the QueryString received from the client is retrieved and a unique registration key is produced and returned to the user.

//Call the Foolproof Registration Key algorithm :)
TheFoolProofRegistrationKey regKey = new TheFoolProofRegistrationKey();
String key = regKey.getRegistrationKey(Request.QueryString["CPU"]);
Response.Write(key);
Notes: If You Decide to Download and Run the Program
If you decide to download and try the application, please make sure to create a virtual folder of the name "Registration" on your local Web server. This is required as the WebRequest is using the following URL: http://localhost/Registration/Registration.aspx (or else copy the files to a folder by the name Registration under the server root folder).

Just for the use of a novice, I have attached a few screen shots on how to add the virtual directory on IIS.


And finally you should have something as follows:

Points of Interest
For testing purposes, I also tried to connect to the server from a different PC: (e.g.: http://10.10.42.135/Registration/Registration.aspx) and it still worked - the firewall did not complain:).
I did not try to connect to a server outside our network, but I guess that should also work...

 

To collect machine specific information, use the code in this article.

Posted by SB패밀리

using System;
using System.Management;
using System.Security.Cryptography;
using System.Security;
using System.Collections;
using System.Text;
namespace Security
{
    /// <summary>
    /// Generates a 16 byte Unique Identification code of a computer
    /// Example: 4876-8DB5-EE85-69D3-FE52-8CF7-395D-2EA9
    /// </summary>
    public class FingerPrint 
    {
        private static string fingerPrint = string.Empty;
        public static string Value()
        {
            if (string.IsNullOrEmpty(fingerPrint))
            {
                fingerPrint = GetHash("CPU >> " + cpuId() + "\nBIOS >> " +
   biosId() + "\nBASE >> " + baseId()
                            //+"\nDISK >> "+ diskId() + "\nVIDEO >> " +
   videoId() +"\nMAC >> "+ macId()
                                     );
            }
            return fingerPrint;
        }
        private static string GetHash(string s)
        {
            MD5 sec = new MD5CryptoServiceProvider();
            ASCIIEncoding enc = new ASCIIEncoding();
            byte[] bt = enc.GetBytes(s);
            return GetHexString(sec.ComputeHash(bt));
        }
        private static string GetHexString(byte[] bt)
        {
            string s = string.Empty;
            for (int i = 0; i < bt.Length; i++)
            {
                byte b = bt[i];
                int n, n1, n2;
                n = (int)b;
                n1 = n & 15;
                n2 = (n >> 4) & 15;
                if (n2 > 9)
                    s += ((char)(n2 - 10 + (int)'A')).ToString();
                else
                    s += n2.ToString();
                if (n1 > 9)
                    s += ((char)(n1 - 10 + (int)'A')).ToString();
                else
                    s += n1.ToString();
                if ((i + 1) != bt.Length && (i + 1) % 2 == 0) s += "-";
            }
            return s;
        }
        #region Original Device ID Getting Code
        //Return a hardware identifier
        private static string identifier
  (string wmiClass, string wmiProperty, string wmiMustBeTrue)
        {
            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;
        }
        //Return a hardware identifier
        private static string identifier(string wmiClass, string wmiProperty)
        {
            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 static string cpuId()
        {
            //Uses first CPU identifier available in order of preference
            //Don't get all identifiers, as it is 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;
        }
        //BIOS Identifier
        private static string biosId()
        {
            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");
        }
        //Main physical hard drive ID
        private static string diskId()
        {
            return identifier("Win32_DiskDrive", "Model")
            + identifier("Win32_DiskDrive", "Manufacturer")
            + identifier("Win32_DiskDrive", "Signature")
            + identifier("Win32_DiskDrive", "TotalHeads");
        }
        //Motherboard ID
        private static string baseId()
        {
            return identifier("Win32_BaseBoard", "Model")
            + identifier("Win32_BaseBoard", "Manufacturer")
            + identifier("Win32_BaseBoard", "Name")
            + identifier("Win32_BaseBoard", "SerialNumber");
        }
        //Primary video controller ID
        private static string videoId()
        {
            return identifier("Win32_VideoController", "DriverVersion")
            + identifier("Win32_VideoController", "Name");
        }
        //First enabled network card ID
        private static string macId()
        {
            return identifier("Win32_NetworkAdapterConfiguration",
    "MACAddress", "IPEnabled");
        }
        #endregion
    }
}

 

 

========================================

결과물

 

CPU >> BFEBFBFF000006FB
BIOS >> Phoenix Technologies, LTD6.00 PGOEM20070919000000.000000+000IntelR - 42302e31
BASE >> Biostar Group기반 보드
DISK >> ST3320620AS(표준 디스크 드라이브)3720011194255
MAC >> 00:E0:4D:51:45:1C

 

 

 

CPU >> BFEBFBFF000006FB
BIOS >> Phoenix Technologies, LTD6.00 PGOEM20070919000000.000000+000IntelR - 42302e31
BASE >> Biostar Group기반 보드
암호화 : 129D-6375-4122-54E7-D304-D826-D1E8-684C

Posted by SB패밀리