【问题标题】:How to Get MAC address programatically in c# for a windows mobile 6.0 device如何在 c# 中为 windows mobile 6.0 设备以编程方式获取 MAC 地址
【发布时间】:2011-05-07 19:09:15
【问题描述】:

如何在 c# 中为 windows mobile 6.0 设备以编程方式获取 MAC 地址? .net compatc framework 3.5 不支持 System.Net.NetworkInformation。

【问题讨论】:

    标签: c# .net windows-mobile mac-address


    【解决方案1】:

    我知道这已经有一段时间了,但我需要这个并发现我可以使用上面代码的 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("-");
        }
    }
    

    【讨论】:

      【解决方案2】:

      我们可以在这类问题中使用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;
                      }
                  }
              }
          }
      }
      

      【讨论】:

      • 这使用设备特定库,因此与 Psion 设备一起工作。
      猜你喜欢
      • 2013-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-07
      • 2012-06-05
      • 2010-09-17
      • 2023-03-27
      • 1970-01-01
      相关资源
      最近更新 更多