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