惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News | PayPal Newsroom
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LangChain Blog
S
SegmentFault 最新的问题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Project Zero
Project Zero
P
Privacy & Cybersecurity Law Blog
V
Vulnerabilities – Threatpost
博客园 - 三生石上(FineUI控件)
Recorded Future
Recorded Future
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
T
The Exploit Database - CXSecurity.com
Schneier on Security
Schneier on Security
H
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
M
MIT News - Artificial intelligence
W
WeLiveSecurity
P
Proofpoint News Feed
A
About on SuperTechFans
S
Securelist
I
InfoQ
G
Google Developers Blog
博客园 - 司徒正美
博客园 - 叶小钗
Latest news
Latest news
F
Fortinet All Blogs
G
GRAHAM CLULEY
腾讯CDC
Jina AI
Jina AI
S
Schneier on Security
I
Intezer
V
Visual Studio Blog
美团技术团队
V2EX - 技术
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
罗磊的独立博客
Y
Y Combinator Blog

博客园 - 迷你软件

MySQL 主从同步延迟监控 Test post from Metablog Api 博文阅读密码验证 - 博客园 ASP.NET中的Menu控件在谷歌浏览器下显示异常的解决办法 符合标准的正常工作的对联广告(漂浮广告JS代码) C#:按钮颜色设置 用相对定位实现简单的图片边框阴影效果 如何识别 SQL Server 的版本 2010最危险的编程错误(转) NopCommerce学习:MSSQL 2005 排序规则导致中文编码错误 URL解码时,为什么将加号解码为空? IPv4 to Integer C# 用SQL语句执行存储过程 1.3.6.1.2.1 - SNMP MIB-2 MIB MODULE HOST-RESOURCES-MIB Simple SNMP with SimpleSnmp 浅谈多线程中数据的绑定和赋值 - 迷你软件 - 博客园 SNMP基础简介 SNMP windows OIDs
获取本机MAC地址
迷你软件 · 2010-01-29 · via 博客园 - 迷你软件

需添加引用:System.Management.dll


        
/// <summary>
        
/// 获取本机第一个索引的网卡MAC
        
/// </summary>
        
/// <returns></returns>
        public string GetMacAddress()
        {
            
string mac = "";
            System.Management.ManagementClass mc;
            mc 
= new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
            System.Management.ManagementObjectCollection moc 
= mc.GetInstances();
            
foreach (System.Management.ManagementObject mo in moc)
            {
                
//可以使用 mo.GetText(System.Management.TextFormat.Mof); 获取所有值

                
if (mo["IPEnabled"].ToString().Equals("True"))
                {
                    
////IPSubnet = "255.255.255.255",可能为拨号连接(MAC一般为:00-53-45-00-00-00)
                    if (mo["IPSubnet"!= null)
                    {
                        
//记录是否为无效地址
                        bool isInvalid = false;string[] ipSubnets = (string[])mo["IPSubnet"];
                        
foreach (string ipSubnet in ipSubnets)
                        {
                            
if (ipSubnet.Equals("255.255.255.255"))
                            {
                                isInvalid 
= true;
                                
break;
                            }
                        }
if (!isInvalid)
                        {
                            
//获取第一个MAC
                            mac = mo["MacAddress"].ToString();
                            
break;
                        }
                    }                    
                }
            }
return mac;
        }