9
Linux의 모노 응용 프로그램에서 내 컴퓨터의 MAC 주소를 얻는 방법은 무엇입니까?모노에서 MAC 주소 가져 오기
Linux의 모노 응용 프로그램에서 내 컴퓨터의 MAC 주소를 얻는 방법은 무엇입니까?모노에서 MAC 주소 가져 오기
는 VS2008 및 모노 테스트, MSDN에서 차용 2.4.2.3 (데비안 2.4.2.3 + DFSG-2) :
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();
}
}
}
출력 (리눅스) : 당신의 초기에
Interface information for hera.(none)
Number of interfaces .................... : 2
lo
==
Interface type .......................... : Loopback
Physical address ........................ :
eth0
====
Interface type .......................... : Ethernet
Physical address ........................ : 00-26-xx-xx-xx-xx
감사 RC 응답 –
BitConverter.ToString (address.GetAddressBytes())을 사용하여 몇 줄의 코드를 저장하십시오. – keza