码迷,mamicode.com
首页 > Web开发 > 详细

asp.net 获取静态网关地址

时间:2016-08-06 17:33:52      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Management;
namespace HELLO_WORD_ASP.NET_MVC4.Models
{
public class MacAddress
{

/// <summary>
/// 获取网卡地址信息
/// </summary>
/// <returns></returns>
public string GetNetCardMacAddress()
{

try
{
string macAddress = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
macAddress = mo["MacAddress"].ToString();
break;
}
}
moc = null;
mc = null;
return macAddress;
}
catch
{
return "unknow";
}
}
}
}

注意事项:ManagementClass 代码粘贴出错,这时候将System.Management 添加引用..

asp.net 获取静态网关地址

标签:

原文地址:http://www.cnblogs.com/rancrazy/p/5744442.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!