Use C # to obtain the computer name, IP,MAC information, the following is the source code:
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Net;
Using System.Management;
Namespace Wenanry.net
{
<summary>
Get computer System Information
</summary>
public class Managementsysteminfo
{
<summary>
Get host Name
</summary>
<returns></returns>
public string HostName
{
Get
{
string hostname = Dns.gethostname ();
return hostname;
}
}
<summary>
Get IP Address
</summary>
<returns></returns>
Public list<string> getiplist ()
{
List<string> iplist = new list<string> ();
ipaddress[] AddressList = Dns.gethostentry (this. HostName). AddressList;
for (int i = 0; i < addresslist.length; i++)
{
Iplist.add (Addresslist[i]. ToString ());
}
return iplist;
}
<summary>
Get MAC Address
</summary>
<returns></returns>
Public list<string> getmaclist ()
{
list<string> maclist = new list<string> ();
ManagementClass MC;
MC = new ManagementClass ("Win32_NetworkAdapterConfiguration");
Managementobjectcollection MOC = MC. GetInstances ();
foreach (ManagementObject mo in MOC)
{
if (mo["ipenabled"]. ToString () = = "True")
Maclist.add (mo["MacAddress"). ToString ());
}
return maclist;
}
}
}