zoukankan      html  css  js  c++  java
  • C# WIN 生成机器码

    内容归档,不多赘述。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Management;
    using System.Security.Cryptography;
    using System.Text;
    
    namespace MachineCode
    {
        public class MachineCode
        {
    
            public static string GetMachineCode()
            {
                try
                {
                    string rs = ToReverse(To_md5(GetCpuInfo() + GetMoAddress() + GetHDid()));
                    return rs;
                }
                catch (Exception ex)
                {
                    return null;
                }
            }
    
            ///   <summary>
            ///   获取cpu序列号    
            ///   </summary>
            ///   <returns> string </returns>
            private static string GetCpuInfo()
            {
                string cpuInfo = " ";
                using (ManagementClass cimobject = new ManagementClass("Win32_Processor"))
                {
                    ManagementObjectCollection moc = cimobject.GetInstances();
                    foreach (ManagementObject mo in moc)
                    {
                        cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
                        mo.Dispose();
                    }
                }
                return cpuInfo.ToString();
            }
    
            ///   <summary>
            ///   获取硬盘ID    
            ///   </summary>
            ///   <returns> string </returns>
            private static string GetHDid()
            {
                string HDid = " ";
                using (ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"))
                {
                    ManagementObjectCollection moc1 = cimobject1.GetInstances();
                    foreach (ManagementObject mo in moc1)
                    {
                        HDid = (string)mo.Properties["Model"].Value;
                        mo.Dispose();
                    }
                }
                return HDid.ToString();
            }
    
            ///   <summary>
            ///   获取网卡硬件地址
            ///   </summary>
            ///   <returns> string </returns>
            private static string GetMoAddress()
            {
                string MoAddress = " ";
                using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
                {
                    ManagementObjectCollection moc2 = mc.GetInstances();
                    foreach (ManagementObject mo in moc2)
                    {
                        if ((bool)mo["IPEnabled"] == true)
                            MoAddress = mo["MacAddress"].ToString();
                        mo.Dispose();
                    }
                }
                return MoAddress.ToString();
            }
    
    
    
    
            /// <summary>
            /// 根据字符串生成MD5
            /// </summary>
            /// <param name="str">原字符串</param>
            /// <param name="up">是否大小写</param>
            /// <returns>生成后的MD5</returns>
            public static string To_md5(string str, bool up = false)
            {
                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                string t2 =
                BitConverter.ToString(md5.ComputeHash(
                UTF8Encoding.Default.GetBytes(str)));
                t2 = t2.Replace("-", "");
                if (!up)
                    return t2.ToLower();
                else
                    return t2.ToUpper();
            }
    
    
            public static string ToReverse(string str)
            {
                return new string(str.ToCharArray().Reverse().ToArray());
            }
        }
    }
  • 相关阅读:
    20174309徐宁艺 Exp7 网络欺诈防范
    20174309徐宁艺 Exp6 MSF基础应用
    20174309徐宁艺 Exp5 信息搜集与漏洞扫描
    20174309徐宁艺 Exp4 恶意代码分析
    20174309徐宁艺 Exp3 免杀原理与实践
    20174309徐宁艺 Exp2 后门原理与实践
    20174309徐宁艺 Exp1 PC平台逆向破解
    Kali Linux安装
    福大软工 · 最终作业
    福大软工 · 第十二次作业
  • 原文地址:https://www.cnblogs.com/myron1024/p/13896375.html
Copyright © 2011-2022 走看看