C # get Cpuid (MD5 output), network card ID, primary DNS, alternate DNS

Source: Internet
Author: User
Tags md5 encryption

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;
Using System.Management;
Using System.Security.Cryptography;
Using System.Net;
Using System.Net.NetworkInformation;
Using System.Text.RegularExpressions;


Namespace WindowsFormsApplication1
{
public partial class Form1:form
{

Public Form1 ()
{
InitializeComponent ();
}

private void Button1_Click (object sender, EventArgs e)
{

}
String txtip= "";
String txtsubmark= "";
String Txtgateway= "";
private void Form1_Load (object sender, EventArgs e)
{
Cpuid
String str = string. Empty;
ManagementClass mccpu = new ManagementClass ("Win32_Processor");
Managementobjectcollection moccpu = Mccpu.getinstances ();
foreach (ManagementObject m in moccpu)
{
str = m["Processorid"]. ToString (). Trim (). Substring (0, 8);//bfebfbff00000f65
}
MD5 encryption
Byte[] result = Encoding.Default.GetBytes (str);
MD5 MD5 = new MD5CryptoServiceProvider ();
byte[] Output = Md5.computehash (result);
This.textBox1.Text = bitconverter.tostring (Output). Replace ("-", "" ");


Get Network Card ID
ManagementClass mc = new ManagementClass ("Win32_NetworkAdapterConfiguration");

Managementobjectcollection MOC2 = MC. GetInstances ();

Managementbaseobject inpar = null;
foreach (ManagementObject mo in moc2)
{

if ((bool) mo["ipenabled"] = = True)

TextBox2.Text = mo["MacAddress"]. ToString ();
Mo. Dispose ();

}


Get Preferred DNS
networkinterface[] nics = networkinterface.getallnetworkinterfaces ();
foreach (NetworkInterface adapter in NICs)
{
BOOL Pd1 = (Adapter.networkinterfacetype = = networkinterfacetype.ethernet); Determine if an Ethernet connection
if (PD1)
{
Ipinterfaceproperties IP = adapter. Getipproperties (); IP configuration information
if (IP. Unicastaddresses.count > 0)
{
Txtip = IP. Unicastaddresses[0]. Address.tostring ();//IP address
Txtsubmark = IP. Unicastaddresses[0]. Ipv4mask.tostring ();//Subnet mask

}
if (IP. Gatewayaddresses.count > 0)
{
Txtgateway = IP. Gatewayaddresses[0]. Address.tostring ();//Default Gateway
}
int dnscount = IP. Dnsaddresses.count;
TextBox3.Text = IP. Dnsaddresses[0]. ToString ();
Textbox4.text = IP. DNSADDRESSES[1]. ToString ();
}
}
}
}
}

C # get Cpuid (MD5 output), network card ID, primary DNS, alternate DNS

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.