博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 获取MAC地址
阅读量:6859 次
发布时间:2019-06-26

本文共 2661 字,大约阅读时间需要 8 分钟。

/********************************************************************** *                         C# 获取MAC地址 * 说明: *     在C#中获取本机的MAC地址,文中提供两个参考,一个是能够所有的MAC * 地址,一个是获取第一个MAC地址。 * *                                  2016-12-9 深圳 南山平山村 曾剑锋 *********************************************************************/一、参考文档:    1. Reliable method to get machine's MAC address in C#        http://stackoverflow.com/questions/850650/reliable-method-to-get-machines-mac-address-in-c-sharp二、解决方法:    using System;    using System.Collections.Generic;    using System.Text;    using System.Net.NetworkInformation;     namespace LocalDetectTest    {        class NetTools        {            ///             /// Finds the MAC address of the NIC with maximum speed.            ///             /// 
The MAC address.
public static void PrintAllMacAddress() { const int MIN_MAC_ADDR_LENGTH = 12; string macAddress = string.Empty; long maxSpeed = -1; foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) { Console.WriteLine( "Name: " + nic.Name + " Found MAC Address: " + nic.GetPhysicalAddress() + " Type: " + nic.NetworkInterfaceType); string tempMac = nic.GetPhysicalAddress().ToString(); if (nic.Speed > maxSpeed && !string.IsNullOrEmpty(tempMac) && tempMac.Length >= MIN_MAC_ADDR_LENGTH) { Console.WriteLine("New Max Speed = " + nic.Speed + ", MAC: " + tempMac); maxSpeed = nic.Speed; macAddress = tempMac; } } // return macAddress; } /// /// Finds the MAC address of the first operation NIC found. /// ///
The MAC address.
public static string GetFirstMacAddress() { string macAddresses = string.Empty; foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) { if (nic.OperationalStatus == OperationalStatus.Up) { macAddresses += nic.GetPhysicalAddress().ToString(); Console.WriteLine(macAddresses); break; } } return macAddresses; } } }

 

转载于:https://www.cnblogs.com/zengjfgit/p/6149713.html

你可能感兴趣的文章
《游戏引擎架构》笔记一
查看>>
pythoy-生成器
查看>>
Redis 分布式锁进化史
查看>>
Java 集合系列05之 LinkedList详细介绍(源码解析)和使用示例
查看>>
Codeforces Round #547 (Div. 3) D
查看>>
(转)如何修正DIV float之后导致的外部容器不能撑开的问题
查看>>
Python全栈开发day9
查看>>
算法笔记 --- Insertion Sort
查看>>
子父表
查看>>
CUDA npp运动检测模块性能测试
查看>>
前端单点登录(SSO)实现方法(二级域名与主域名)
查看>>
extjs客户端与ABP框架的服务端数据交互杂记
查看>>
kali linux fuzz工具集简述
查看>>
微信小程序云开发不完全指北
查看>>
《构建之法》阅读笔记二
查看>>
20165324 前四周总结反思
查看>>
11.11评价
查看>>
第一章--第一节:环境搭建
查看>>
hdu 2665 划分树
查看>>
hdu 4251 划分树
查看>>