亲宝软件园·资讯

展开

C#如何获取mac地址 C#获取计算机名,IP,MAC信息实现代码

人气:0
想了解C#获取计算机名,IP,MAC信息实现代码的相关内容吗,在本文为您仔细讲解C#怎样获取mac地址的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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;
}
}
}

加载全部内容

相关教程
猜你喜欢
用户评论