C # generate the mac ip address of the registration code

Source: Internet
Author: User

Using system; using system. management; using system. security. cryptography; using system. io; using system. collections. generic; using system. text; namespace xingming_reg {class program {static void main (string [] ARGs) {bool sucsess = false; string computerbit = ""; regmutou Reg = new regmutou (); computerbit = reg. getcomputerbit ("X"); sucsess = reg. regmutousoft (computerbit, "Xinmin", "Xinmin. USR "); consol E. writeline (sucsess); console. readline () ;}} internal class regmutou {// Methods Public String getbiosserialnumber () {try {managementobjectsearcher searcher = new managementobjectsearcher ("select * From win32_bios "); string STR = ""; foreach (managementobject obj2 in searcher. get () {STR = obj2 ["serialnumber"]. tostring (). trim () ;}return STR ;}catch {return "" ;}} Public String getcomputer Bit (string softname) {string cpuid = This. getcpuid (); string biosserialnumber = This. getbiosserialnumber (); string harddiskserialnumber = This. getharddiskserialnumber (); string netcardmacaddress = This. getnetcardmacaddress (); If (cpuid! = "") {MD5 MD = new md5cryptoserviceprovider (); cpuid = bitconverter. tostring (MD. computehash (encoding. default. getbytes (cpuid ))). replace ("-",""). toupper (). substring (8, 0x10); Return (softname + "C" + cpuid);} If (biosserialnumber! = "") {MD5 md2 = new md5cryptoserviceprovider (); biosserialnumber = bitconverter. tostring (md2.computehash (encoding. default. getbytes (biosserialnumber ))). replace ("-",""). toupper (). substring (8, 0x10); Return (softname + "B" + biosserialnumber);} If (harddiskserialnumber! = "") {MD5 md3 = new md5cryptoserviceprovider (); harddiskserialnumber = bitconverter. tostring (md3.computehash (encoding. default. getbytes (harddiskserialnumber ))). replace ("-",""). toupper (). substring (8, 0x10); Return (softname + "H" + harddiskserialnumber);} If (netcardmacaddress! = "") {MD5 md4 = new md5cryptoserviceprovider (); netcardmacaddress = bitconverter. tostring (md4.computehash (encoding. default. getbytes (netcardmacaddress ))). replace ("-",""). toupper (). substring (8, 0x10); Return (softname + "N" + netcardmacaddress);} return (softname + "wf53a419db238bbad");} Public String getcpuid () {try {managementobjectcollection instances = new managementclass ("win32_processor" ). Getinstances (); string STR = NULL; foreach (managementobject obj2 in instances) {STR = obj2.properties ["processorid"]. value. tostring (); break;} return STR;} catch {return "" ;}} Public String getharddiskserialnumber () {try {managementobjectsearcher searcher = new managementobjectsearcher ("select * From win32_physicalmedia"); string STR = ""; foreach (managementobject obj2 in searcher. get () {STR = obj2 ["serialnumber"]. tostring (). trim (); break;} return STR;} catch {return "" ;}} Public String getnetcardmacaddress () {try {managementobjectsearcher searcher = new managementobjectsearcher ("select * From win32_networkadapter where (macaddress is not null) and (manufacturer <> 'Microsoft '))"); string STR = ""; foreach (managementobject obj2 in searcher. get () {STR = obj2 ["macadd RESS "]. tostring (). trim () ;}return STR ;}catch {return "" ;}} public bool regmutousoft (string computerbit, string softname, string filename) {bool flag = true; string STR = ""; sha1 Sha = new sha1cryptoserviceprovider (); STR = bitconverter. tostring (Sha. computehash (encoding. default. getbytes (softname ))). replace ("-",""). toupper (); // If (! File. exists (filename) // {// flag = false; // stream = file. open (filename, filemode. openorcreate); // streamwriter writer = new streamwriter (Stream); // writer. writeline (computerbit); // writer. close (); // stream. close (); // return flag; //} // stream stream2 = file. open (filename, filemode. open); // streamreader reader = new streamreader (stream2); // string str2 = ""; string str3 = computerbit; // While (str2 = reader. Readline ())! = NULL) // {// str3 = str2; //} // reader. Close (); // stream2.close (); // If (str3.length! = 0x18) // {// return false; //} sha1 sha2 = new sha1cryptoserviceprovider (); string str4 = bitconverter. tostring (sha2.computehash (encoding. default. getbytes (computerbit ))). replace ("-",""). toupper (); string str5 = ""; for (INT I = 0; I <str4.length; I ++) {If (I % 2) = 1) {str5 = str5 + str4 [I] ;}} string str6 = ""; for (Int J = 0; j <Str. length; j ++) {If (J % 2) = 0) {str6 = str6 + STR [J] ;}} int [] numarray = new int [20]; for (int K = 0; k <20; k ++) {numarray [k] = str6 [k] + str5 [k]; numarray [k] = numarray [k] % 0x24;} string str7 = ""; for (INT m = 0; m <20; m ++) {If (M> 0) & (M % 4) = 0 )) {str7 = str7 + "-";} str7 = str7 + "0123456789 abcdefghijklmnopqrstuvwxyz" [numarray [m];} If (str3 = str7) {flag = true ;} console. writeline ("machine code:" + str3); console. writeline ("Registration Code:" + str7); Return flag ;}}}

Http://www.oschina.net/code/snippet_104837_2095

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

Using system. management; // win32_networkadapterconfiguration is the information table managementobjectsearcher query = new managementobjectsearcher ("select * From win32_networkadapterconfiguration where ipenabled = 'true'") in the WMI database '"); // The managementobjectcollection object is used to store the query result. managementobjectcollection querycollection = query. get (); foreach (managementobject Mo in querycollection) {console. writeline ("network card: {0}", Mo ["Description"]); console. writeline ("MAC address: {0}", Mo ["macaddress"]); // addresses, subnets, and ultultgateways values can both contain multiple worthwhile arrays. // to adapt to this situation, you must allocate the result to a string array to adapt to this situation, // use the foreach statement again to use the string array string [] addresses = (string []) Mo ["IPaddress"]; string [] subnets = (string []) mo ["ipsubnet"]; string [] defaultgateways = (string []) Mo ["defaultipgateway"]; // any interface may have multiple IP addresses foreach (string IPaddress in addresses) {console. writeline ("IP Address: {0}", IPaddress);} foreach (string subnet in subnets) {console. writeline ("subnet mask: {0}", subnet);} foreach (string DefaultGateway in defaultgateways) {console. writeline ("Gateway: {0}", DefaultGateway);} console. writeline ();}

Http://blog.csdn.net/luols/article/details/5803135

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.