阅读:在.NET网卡MAC地址 [英] Read MAC Address from network adapter in .NET

查看:174
本文介绍了阅读:在.NET网卡MAC地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够读取第一个活动的网络适配器使用VB.net或C#(使用.NET 3.5 SP1)的WinForm应用程序的mac地址

I'd like to be able to read the mac address from the first active network adapter using VB.net or C# (using .NET 3.5 SP1) for a winform application

推荐答案

由于NET 2.0也一直在给你这些信息的System.Net.NetworkInformation命名空间NetworkInterface类。试试这个:

Since .Net 2.0 there's been a NetworkInterface class in the System.Net.NetworkInformation namespace that will give you this information. Try this:

        foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
        {
            if (nic.OperationalStatus == OperationalStatus.Up)
            {
                Console.WriteLine(nic.GetPhysicalAddress().ToString());
                break;
            }
        }

这篇关于阅读:在.NET网卡MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆