如何在 C# 中以编程方式获取 Windows Mobile 6.0 设备的 MAC 地址

发布于 2024-10-01 04:13:57 字数 115 浏览 5 评论 0原文

如何在 C# 中以编程方式获取 Windows Mobile 6.0 设备的 MAC 地址? .net compatc Framework 3.5 不支持 System.Net.NetworkInformation。

How to Get MAC address programatically in c# for a windows mobile 6.0 device? The System.Net.NetworkInformation is not supported in ,net compatc framework 3.5.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人事已非 2024-10-08 04:13:57

我知道已经有一段时间了,但我需要这个,并发现我可以使用上面代码的 OpenNETCF 版本进行调整:

INetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
//for each j you can get the MAC 
PhysicalAddress address = nics[0].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("-");
    }
}

I know it's been awhile, but I needed this and found I could use OpenNETCF version of the code above with a tweak:

INetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
//for each j you can get the MAC 
PhysicalAddress address = nics[0].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("-");
    }
}
千里故人稀 2024-10-08 04:13:57

我们可以使用 MDSDK 来解决此类问题,例如

using PsionTeklogix.Peripherals;
namespace EnumAdapters
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            ArrayList pList = null;
            string[] lStatistic = null;

            try
            {
                pList = Peripherals.EnumerateAdapters();
            }
            catch (Exception ex)
            {
                MessageBox.Show("failed with\r\n" + ex.Message, "EnumerateAdapters()");
                Close();
                return;
            }

            listBox1.Items.Clear();

            foreach (string AdapterName in pList)
            {
                try
                {
                    listBox1.Items.Add(AdapterName + (Peripherals.IsAdapterPresent(AdapterName) ? " is present" : " is NOT present") + (Peripherals.IsWirelessAdapter(AdapterName) ? " [wireless adapter] " : ""));
                    lStatistic = Peripherals.GetAdapterStatistics(AdapterName); // See Note 1
                    foreach (string StatInfo in lStatistic)
                    {
                        if (StatInfo.StartsWith("Local MAC Address"))
                        {
                            listBox1.Items.Add("» " + StatInfo);
                            break;
                         }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    Close();
                    return;
                }
            }
        }
    }
}

We can use MDSDK in this type of problems like

using PsionTeklogix.Peripherals;
namespace EnumAdapters
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            ArrayList pList = null;
            string[] lStatistic = null;

            try
            {
                pList = Peripherals.EnumerateAdapters();
            }
            catch (Exception ex)
            {
                MessageBox.Show("failed with\r\n" + ex.Message, "EnumerateAdapters()");
                Close();
                return;
            }

            listBox1.Items.Clear();

            foreach (string AdapterName in pList)
            {
                try
                {
                    listBox1.Items.Add(AdapterName + (Peripherals.IsAdapterPresent(AdapterName) ? " is present" : " is NOT present") + (Peripherals.IsWirelessAdapter(AdapterName) ? " [wireless adapter] " : ""));
                    lStatistic = Peripherals.GetAdapterStatistics(AdapterName); // See Note 1
                    foreach (string StatInfo in lStatistic)
                    {
                        if (StatInfo.StartsWith("Local MAC Address"))
                        {
                            listBox1.Items.Add("» " + StatInfo);
                            break;
                         }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    Close();
                    return;
                }
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文