zoukankan      html  css  js  c++  java
  • netcore获取MAC地址

     1      /// <summary>
     2         /// 获取电脑 MAC(物理) 地址
     3         /// </summary>
     4         /// <returns></returns>
     5         public string GetMACIp()
     6         {
     7             //本地计算机网络连接信息
     8             IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
     9             //获取本机所有网络连接
    10             NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
    11 
    12             //获取本机电脑名
    13             var HostName = computerProperties.HostName;
    14             //获取域名
    15             var DomainName = computerProperties.DomainName;
    16 
    17             if (nics == null || nics.Length < 1)
    18             {
    19                 return "";
    20             }
    21 
    22             var MACIp = "";
    23             foreach (NetworkInterface adapter in nics)
    24             {
    25                 var adapterName = adapter.Name;
    26 
    27                 var adapterDescription = adapter.Description;
    28                 var NetworkInterfaceType = adapter.NetworkInterfaceType;
    29                 if (adapterName == "本地连接")
    30                 {
    31                     PhysicalAddress address = adapter.GetPhysicalAddress();
    32                     byte[] bytes = address.GetAddressBytes();
    33 
    34                     for (int i = 0; i < bytes.Length; i++)
    35                     {
    36                         MACIp += bytes[i].ToString("X2");
    37 
    38                         if (i != bytes.Length - 1)
    39                         {
    40                             MACIp += "-";
    41                         }
    42                     }
    43                 }
    44             }
    45 
    46             return MACIp;
    47         }
  • 相关阅读:
    vSphere vCenter的个人理解及问题
    服务器账号过期处理
    虚拟化初探引入
    win10虚拟机跨网段迁移
    win7远程执行win10的抓取代码
    Jenkins+Sonar质量门禁【实践篇pipeline版】
    ELK7.10 license过期处理
    php 0108
    php 0110
    php 0111
  • 原文地址:https://www.cnblogs.com/jimmyLei/p/11165363.html
Copyright © 2011-2022 走看看