C # obtain CPUID (MD5 output), Nic ID, primary DNS, backup DNS,

Source: Internet
Author: User

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 ();
}
}
}
}
}

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.