当前位置:网站首页>C#获取网卡地址

C#获取网卡地址

2022-08-09 08:56:00 l8487

using System;
using System.Management;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class main : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
        ManagementObjectCollection moc = mc.GetInstances();
        foreach (ManagementObject mo in moc)
        {
            if ((bool)mo["IPEnabled"] == true)
                Label1.Text = mo["MacAddress"].ToString();

        }
    }
}

好简单的代码啊。但是需要using System.Management;

引入方法是菜单“网站”-“添加引用”-net中的System.Management。。就可以了。。

原网站

版权声明
本文为[l8487]所创,转载请带上原文链接,感谢
https://blog.csdn.net/l8487/article/details/2174145