可靠的方法来获得在C#机的MAC地址 [英] Reliable method to get machine's MAC address in C#

查看:258
本文介绍了可靠的方法来获得在C#机的MAC地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方式来获得一台机器的MAC地址,无论是使用C#运行的操作系统的。应用程序将需要在XP / VISTA / Win7的32位和64位,以及对这些操作系统而是一门外语默认工作。许多C#命令和操作系统查询不跨操作系统的运行。有任何想法吗?我一直在刮IPCONFIG / ALL的输出,但输出格式每台机器上的不同,这是非常不可靠的。

I need a way to get a machine's MAC address regardless of the OS it is running using C#. Application will need to work on XP/Vista/Win7 32 and 64 bit as well as on those OSs but with a foreign language default. Many of the C# commands and OS queries don't work across OS. Any ideas? I have been scraping the output of "ipconfig /all" but this is terribly unreliable as the output format differs on every machine.

感谢

推荐答案

清洁的解决方案

var macAddr = 
    (
        from nic in NetworkInterface.GetAllNetworkInterfaces()
        where nic.OperationalStatus == OperationalStatus.Up
        select nic.GetPhysicalAddress().ToString()
    ).FirstOrDefault();

这篇关于可靠的方法来获得在C#机的MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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