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{/// /// 获取计算机系统信息/// public class ManagementSy
利用C#获取计算机名,IP,MAC信息,如下为源代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Management;
namespace Wenanry.Net
{
///
/// 获取计算机系统信息
///
public class ManagementSystemInfo
{
///
/// 获取主机名
///
///
public string HostName
{
get
{
string hostname = Dns.GetHostName();
return hostname;
}
}
///
/// 获取IP地址
///
///
public List GetIPList()
{
List ipList = new List();
IPAddress[] addressList = Dns.GetHostEntry(this.HostName).AddressList;
for (int i = 0; i < addressList.Length; i++)
{
ipList.Add(addressList[i].ToString());
}
return ipList;
}
///
/// 获取Mac地址
///
///
public List getMacList()
{
List macList = new List();
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;
}
}
}
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)