Obtain the computer name, IP address, and MAC address:
Private void button1_Click_1 (object sender, System. EventArgs e)
{
String s = "", mac = "";
//
// Name
//
String hostInfo = Dns. GetHostName ();
//
// IP
System. Net. IPAddress [] addressList = Dns. GetHostByName (Dns. GetHostName (). AddressList;
For (int I = 0; I <addressList. Length; I ++)
{
S + = addressList [I]. ToString ();
}
//
// Mac
//
ManagementClass mc;
Mc = new ManagementClass ("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection moc = mc. GetInstances ();
Foreach (ManagementObject mo in moc)
{
If (mo ["IPEnabled"]. ToString () = "True ")
Mac = mo ["MacAddress"]. ToString ();
}
TxtName. Text = hostInfo;
TxtIp. Text = s;
TxtMac. Text = mac;
Button1.Enabled = false;
Button2.Focus ();
}---------------------------------------------------------------------
Obtain the computer name, IP address, and MAC address:
Private void button1_Click_1 (object sender, System. EventArgs e)
{
String s = "", mac = "";
//
// Name
//
String hostInfo = Dns. GetHostName ();
//
// IP
System. Net. IPAddress [] addressList = Dns. GetHostByName (Dns. GetHostName (). AddressList;
For (int I = 0; I <addressList. Length; I ++)
{
S + = addressList [I]. ToString ();
}
//
// Mac
//
ManagementClass mc;
Mc = new ManagementClass ("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection moc = mc. GetInstances ();
Foreach (ManagementObject mo in moc)
{
If (mo ["IPEnabled"]. ToString () = "True ")
Mac = mo ["MacAddress"]. ToString ();
}
TxtName. Text = hostInfo;
TxtIp. Text = s;
TxtMac. Text = mac;
Button1.Enabled = false;
Button2.Focus ();
}