VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > C/C++语言编程 >
  • C#教程之C#获取计算机名,IP,MAC信息实现代码

 利用C#获取计算机名,IP,MAC信息,如下为源代码:
复制代码 代码如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Management;
namespace Wenanry.Net
{
/// <summary>
/// 获取计算机系统信息
/// </summary>
public class ManagementSystemInfo
{
/// <summary>
/// 获取主机名
/// </summary>
/// <returns></returns>
public string HostName
{
get
{
string hostname = Dns.GetHostName();
return hostname;
}
}
/// <summary>
/// 获取IP地址
/// </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>
/// 获取Mac地址
/// </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;
}
}
相关教程