C#通过WMI读取MAC地址
该方法依赖WMI的系统服务,该服务一般不会被关闭;但如果系统服务缺失或者出现问题,该方法无法取得MAC地址,需要重启Windows Management Instrumentation服务。
public static string GetMacAddress()
{
try
{
string active_mac = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
active_mac = mo["MacAddress"].ToString();
mo.Dispose();
}
string mac = active_mac.Substring(0, 2) + active_mac.Substring(3, 2) + active_mac.Substring(6, 2) + active_mac.Substring(9, 2) + active_mac.Substring(12, 2) + active_mac.Substring(15, 2);
return mac;
}
catch (Exception ex)
{
return "Error Mac." + ex.Message;
}
}
复制代码 (编辑:雷林鹏 来源:网络)
C#通过WMI读取MAC地址的更多相关文章
- 几种C#程序读取MAC地址的方法
原文:几种C#程序读取MAC地址的方法 以下是收集的几种C#程序读取MAC地址的方法,示例中是读取所有网卡的MAC地址,如果仅需要读取其中一个,稍作修改即可. 1 通过IPConfig命令读取MAC地 ...
- C# 几种读取MAC地址的方法
以下是收集的几种C#程序读取MAC地址的方法,示例中是读取所有网卡的MAC地址,如果仅需要读取其中一个,稍作修改即可. 1 通过IPConfig命令读取MAC地址 ///<summary> ...
- C#中通过SendARP读取MAC地址
C#中通过SendARP读取MAC地址: using System.Runtime.InteropServices; publicstaticstring GetMacBySendARP(string ...
- C#程序读取MAC地址的五种方法(转)
public class GetMac { ///<summary> /// 根据截取ipconfig /all命令的输出流获取网卡Mac ///</summary> ///& ...
- (转)C#读取MAC的几种方法
原文地址:http://www.cnblogs.com/diulela/archive/2012/04/07/2436111.html 1 通过IPConfig命令读取MAC地址 ///<sum ...
- 获取客户端Mac地址
近期有个需求,需要获取客户端Mac地址作为白名单验证的依据.使用.net,B/S架构.先百度找了一些获取mac地址的方法, using System; using System.Collections ...
- 读取Android设备的MAC地址
读取Android设备的MAC地址 AndroidUtil.java package com.csdn.android.util; import com.csdn.android.framewor ...
- 如何获取客户端MAC地址(三个方法)
方法一: 调用Windows的DOS命令,从输出结果中读取MAC地址: public static String getMACAddress() { String address = "&q ...
- Android 获取WIFI MAC地址的方法
1. 经常用法,调用Android的API:WifiManager <uses-permission android:name="android.permission.ACCESS_W ...
随机推荐
- loadrunner多场景的串行执行以及定时执行
方法一: 既然是脚本串行执行,那在场景设计中必然是要用多个脚本,要注意的是需要将Scenario Schedule中的Schedule by设置为Group的模式.然后按实际需要依次设置每个脚本的Sc ...
- [ASP.NET 大牛之路]02 - C#高级知识点概要(1) - 委托和事件
在ASP.NET MVC 小牛之路系列中,前面用了一篇文章提了一下C#的一些知识点.照此,ASP.NET MVC 大牛之路系列也先给大家普及一下C#.NET中的高级知识点.每个知识点不太会过于详细,但 ...
- Gitlab安装和使用
GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目. GitLab拥有与Github类似 ...
- codeforces#505--B Weakened Common Divisor
B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input ...
- 我见过的最完善的log4net配置
Log4net的优点: 几乎所有的大型应用都会有自己的用于跟踪调试的API.因为一旦程序被部署以后,就不太可能再利用专 门的调试工具了.然而 一个管理员可能需要有一套强大的日志系统来诊断和修复配置上的 ...
- Day22 文件上传下载和javaMail
day22总结 文件上传概述 1 文件上传的作用 例如网络硬盘!就是用来上传下载文件的. 在智联招聘上填写一个完整的简历还需要上传照片呢. 2 文件上传对页面的要求 上传文件的要求比较多,需要 ...
- Linux下如何执行Shell脚本
Linux下你可以有两种方式执行Shell脚本: 1.用shell程序执行脚本:根据你的shell脚本的类型,选择shell程序,常用的有sh,bash,tcsh等(一般来说第一行#!/bin/bas ...
- word安装mathtype
1:window版本的mathtype:https://pan.baidu.com/s/1Yn8kPG9Y9nBPGaotFJaL2Q ,密码spwm 2:点击exe安装 (安装到c盘,将不会出 ...
- ScyllaDB - 基础部署
基础环境 操作系统: CentOS 7.2: 集群节点(虚拟机):172.16.134.15 ~ 17: 基础准备 安装依赖和卸载 abrt ( abrt 和 coredump 配置冲突 ): sud ...
- redis客户端hiredis
Hiredis 在官网 http://redis.io/clients 中有说明This is the official C client. Support for the whole command ...