using System;using System.Net.networkinformation;namespace ConsoleApplication2{ class Program { public static voID ShowNetworkInterfaces() { IPGlobalPropertIEs computerPropertIEs = IPGlobalPropertIEs.GetIPGlobalPropertIEs(); NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); Console.Writeline("Interface information for {0}.{1} ",computerPropertIEs.Hostname,computerPropertIEs.Domainname); if (nics == null || nics.Length < 1) { Console.Writeline(" No network interfaces found."); return; } Console.Writeline(" Number of interfaces .................... : {0}",nics.Length); foreach (NetworkInterface adapter in nics) { Console.Writeline(); Console.Writeline(adapter.Description); Console.Writeline(String.Empty.Padleft(adapter.Description.Length,'=')); Console.Writeline(" Interface type .......................... : {0}",adapter.Netwo$ Console.Write(" Physical address ........................ : "); PhysicalAddress address = adapter.GetPhysicalAddress(); byte[] bytes = address.GetAddressBytes(); for (int i = 0; i < bytes.Length; i++) { // display the physical address in hexadecimal. Console.Write("{0}",bytes[i].ToString("X2")); // Insert a hyphen after each byte,unless we are at the end of the // address. if (i != bytes.Length - 1) { Console.Write("-"); } } Console.Writeline(); } } static voID Main(string[] args) { ShowNetworkInterfaces(); } }}
输出(linux):
Interface information for hera.(none) Number of interfaces .................... : 2lo== Interface type .......................... : Loopback Physical address ........................ :eth0==== Interface type .......................... : Ethernet Physical address ........................ : 00-26-xx-xx-xx-xx总结
以上是内存溢出为你收集整理的c# – 使用单声道获取linux中的MAC地址全部内容,希望文章能够帮你解决c# – 使用单声道获取linux中的MAC地址所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)