C# 获取机器码Code

 

ContractedBlock.gif ExpandedBlockStart.gif Code
 1None.gifusing System;
 2None.gifusing System.Management;
 3None.gifusing System.IO;
 4None.gifusing System.Runtime.InteropServices;
 5None.gifusing System.Security.Cryptography;
 6None.gifusing System.Text;
 7None.gifusing Microsoft.Win32;
 8None.gif
 9None.gifnamespace CHUmanager.Common
10ExpandedBlockStart.gifContractedBlock.gifdot.gif{
11ExpandedSubBlockStart.gifContractedSubBlock.gif    /**////  <summary> 
12InBlock.gif    /// register 的摘要说明。 
13InBlock.gif    /// 注册软件所用到的类 
16ExpandedSubBlockEnd.gif    ///  </summary> 

17InBlock.gif    public class Register
18ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
19InBlock.gif
20ContractedSubBlock.gifExpandedSubBlockStart.gif        获取cpu序列号 硬盘ID 网卡硬地址#region 获取cpu序列号 硬盘ID 网卡硬地址
21ExpandedSubBlockStart.gifContractedSubBlock.gif        /**////  <summary> 
22InBlock.gif        /// 获取cpu序列号   
23InBlock.gif        ///  </summary> 
24ExpandedSubBlockEnd.gif        ///  <returns>string </returns> 

25InBlock.gif        public string GetCpuInfo()
26ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
27InBlock.gif            string cpuInfo = "";
28InBlock.gif            ManagementClass cimobject = new ManagementClass("Win32_Processor");
29InBlock.gif            ManagementObjectCollection moc = cimobject.GetInstances();
30InBlock.gif            foreach (ManagementObject mo in moc)
31ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
32InBlock.gif                cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
33ExpandedSubBlockEnd.gif            }

34InBlock.gif            return cpuInfo.ToString();
35ExpandedSubBlockEnd.gif        }

36InBlock.gif
37ExpandedSubBlockStart.gifContractedSubBlock.gif        /**////  <summary> 
38InBlock.gif        /// 获取硬盘ID   
39InBlock.gif        ///  </summary> 
40ExpandedSubBlockEnd.gif        ///  <returns>string </returns> 

41InBlock.gif        public string GetHDid()
42ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
43InBlock.gif            string HDid = "";
44InBlock.gif            ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
45InBlock.gif            ManagementObjectCollection moc1 = cimobject1.GetInstances();
46InBlock.gif            foreach (ManagementObject mo in moc1)
47ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
48InBlock.gif                HDid = (string)mo.Properties["Model"].Value;
49ExpandedSubBlockEnd.gif            }

50InBlock.gif            return HDid.ToString();
51ExpandedSubBlockEnd.gif        }

52InBlock.gif
53ExpandedSubBlockStart.gifContractedSubBlock.gif        /**////  <summary> 
54InBlock.gif        /// 获取网卡硬件地址 
55InBlock.gif        ///  </summary> 
56ExpandedSubBlockEnd.gif        ///  <returns>string </returns> 

57InBlock.gif        public string GetMoAddress()
58ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
59InBlock.gif            string MoAddress = "";
60InBlock.gif            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
61InBlock.gif            ManagementObjectCollection moc2 = mc.GetInstances();
62InBlock.gif            foreach (ManagementObject mo in moc2)
63ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
64InBlock.gif                if ((bool)mo["IPEnabled"== true)
65InBlock.gif                    MoAddress = mo["MacAddress"].ToString();
66InBlock.gif                mo.Dispose();
67ExpandedSubBlockEnd.gif            }

68InBlock.gif            return MoAddress.ToString();
69ExpandedSubBlockEnd.gif        }

70ExpandedSubBlockEnd.gif        #endregion

71ExpandedSubBlockEnd.gif    }

72ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/feinian/archive/2008/04/06/1139653.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然,我可以为您提供一个简单的示例。以下是一个使用编写的基本器码验证注册系统的示例: ```sharp using System; using System.Management; using System.Security.Cryptography; using System.Text; namespace MachineCodeVerification { class Program { static void Main(string[]) { string machine = GetMachineCode(); Console.WriteLine("请提供注册码:"); string registrationCode = Console.ReadLine(); if (VerifyRegistrationCode(machineCode, registrationCode)) { Console.WriteLine("注册成功!"); } else Console.WriteLine("注册失败!"); } Console.ReadLine(); } static string GetMachineCode() { string cpuId = GetCPUId(); string volumeSerial = GetVolumeSerial(); string machineCode = cpuId + volumeSerial; return machineCode; } static string GetCPUId() { string cpuId = string.Empty; ManagementClass mc = new ManagementClass("win32_processor"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { cpuId = mo.Properties["processorID"].Value.ToString(); break; } return cpuId; } static string GetVolumeSerial() { string volumeSerial = string.Empty; ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\""); disk.Get(); volumeSerial = disk["VolumeSerialNumber"].ToString(); return volumeSerial; } static bool VerifyRegistrationCode(string machineCode, string registrationCode) { string hashedMachineCode = HashMachineCode(machineCode); // 在此处进行注册码验证逻辑,例如:将注册码与加密后的机器码进行比较 return registrationCode == hashedMachineCode; } static string HashMachineCode(string machineCode) { using (SHA256 sha256Hash = SHA256.Create()) { byte[] data = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(machineCode)); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < data.Length; i++) { stringBuilder.Append(data[i].ToString("x2")); } return stringBuilder.ToString(); } } } } ``` 这个示例程序通过获取CPU ID和卷序列号来生成机器码,并使用SHA256哈希算法对机器码进行加密。然后,您可以在`VerifyRegistrationCode`方法中编写注册码验证逻辑,例如将注册码与加密后的机器码进行比较。 请注意,这只是一个简单的示例程序,实际的机器码验证注册系统应该包含更复杂的算法和安全措施以防止盗版和破解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值