当前位置: 移动技术网 > IT编程>开发语言>c# > C#获取计算机名,IP,MAC信息实现代码

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

2019年07月18日  | 移动技术网IT编程  | 我要评论
利用c#获取计算机名,ip,mac信息,如下为源代码: 复制代码 代码如下: using system; using system.collections.generic;
利用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;
}
}
}

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网