C # obtain CPUID (MD5 output), Nic ID, primary DNS, backup DNS,
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 button#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 ("-","");
// Obtain the NIC 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 ();
}
// Obtain the preferred dns
NetworkInterface [] interfaces = NetworkInterface. GetAllNetworkInterfaces ();
Foreach (NetworkInterface adapter in progress)
{
Bool Pd1 = (adapter. NetworkInterfaceType = NetworkInterfaceType. Ethernet); // you can check whether the connection is over Ethernet.
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 ();
}
}
}
}
}