Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用c获取mac os x设备的物理地址#_C#_Cocoa_Visual Studio Mac - Fatal编程技术网

C# 如何使用c获取mac os x设备的物理地址#

C# 如何使用c获取mac os x设备的物理地址#,c#,cocoa,visual-studio-mac,C#,Cocoa,Visual Studio Mac,我正在使用visual studio for mac,使用c#。我尝试了system.net.networkinformation,但它给了我一个空白字符串 foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) { if (nic.OperationalStatus == OperationalStatus.Up)

我正在使用visual studio for mac,使用c#。我尝试了system.net.networkinformation,但它给了我一个空白字符串

foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (nic.OperationalStatus == OperationalStatus.Up)
                {
                    mac += nic.GetPhysicalAddress().ToString();
                    //Console.WriteLine(mac);
                    break;
                }
            }

这是我用来获取mac地址的。它在windows桌面应用程序中运行良好,但在os x中不起作用。我正在尝试获取mac桌面的mac地址,以获取其唯一标识

下面的函数给出了我需要的确切mac地址

  public static string GetMacAddress()
        {
            System.Net.NetworkInformation.NetworkInterfaceType Type = 0;
            string MacAddress = string.Empty;
            try
            {
                System.Net.NetworkInformation.NetworkInterface[] theNetworkInterfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
                foreach (System.Net.NetworkInformation.NetworkInterface currentInterface in theNetworkInterfaces)
                {
                    Type = currentInterface.NetworkInterfaceType;
                    if (Type == System.Net.NetworkInformation.NetworkInterfaceType.Ethernet || Type == System.Net.NetworkInformation.NetworkInterfaceType.GigabitEthernet || Type == System.Net.NetworkInformation.NetworkInterfaceType.FastEthernetFx)
                    {
                        MacAddress = currentInterface.GetPhysicalAddress().ToString();
                        break;
                    }
                }

                return MacAddress;

            }
            catch 
            {
                // your code goes here

            }

        }

你能给你的问题补充一些细节吗?此外,请阅读hi,请立即检查。您正在使用
Xamarin.Mac
?如果您试图获取唯一的id,请使用
IOPlatformUUID
(通过I/O工具包),而不是接口的Mac地址,因为这些地址很容易被欺骗。不,我正在使用visual studio for Mac。还有其他唯一识别设备的方法吗?我从这里得到了答案