C # Get computer name, IP,MAC information Implementation Code _c# tutorial

Source: Internet
Author: User
Tags get ip
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;
}
}
}
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.