C#教程

关注公众号 jb51net

关闭
首页 > 软件编程 > C#教程 > C#如何获取mac地址

C#获取计算机名,IP,MAC信息实现代码

作者:

利用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;
}
}
}
您可能感兴趣的文章:
阅读全文