本人所使用的開發環境是vs2008,開發的系統所在移動終端版本為windows mobile 5.0。由於需要進行身份的驗證,需要獲取移動終端的mac位址,於是在網上進行搜尋,主要看到了三種方法來實現獲取mac位址,現記錄如下。
第一種方法:使用managementclass 來獲取。
殊不知,wince下並沒有system.management,這種方法根本行不通。
第二種方法:通過查詢登錄檔來獲取mac位址。
這是獲取登錄檔位址的**:
txtmac1.text = reg.readvalue(yfreg.hkey.hkey_local_machine, @"comm\dm9ce1\parms", "softwaremacaddress0");
第三種方法:通過sendarp獲取mac位址。
**如下:
通過 ip helper api 中的 sendarp 傳送 arp 請求可以用來獲取指定ip位址的mac 位址,簡單方便,缺點是不能跨越閘道器。using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.windows.forms;
using system.collections;
using system.diagnostics;
using system.runtime.interopservices;
using system.io;
using system.security.cryptography;
using system.net;
namespace wirelessroutesystem
; private static int32 method_buffered = 0;
private static int32 file_any_access = 0;
private static int32 file_device_hal = 0x00000101;
private const int32 error_not_supported = 0x32;
private const int32 error_insufficient_buffer = 0x7a;
private static int32 ioctl_hal_get_deviceid = ((file_device_hal) << 16) | ((file_any_access) << 14) | ((21) << 2) | (method_buffered);
[dllimport("coredll.dll", setlasterror = true)]
private static extern bool kerneliocontrol(int32 dwiocontrolcode, intptr lpinbuf, int32 ninbufsize, byte lpoutbuf, int32 noutbufsize, ref int32 lpbytesreturned);
[dllimport("iphlpapi.dll", entrypoint = "sendarp")]
public static extern uint sendarp(uint destip, uint srcip, byte pmacaddr, ref uint phyaddrlen);
/// /// 獲取mac位址
///
///
public string getmac()
return mac;
}/// ///獲取本機ip
///
///
public string getipaddress()
}}
至於獲取ip位址,本文已經給出了兩種方法,都是通過net下dns類中方法獲取。
ZZ linux中獲取IP和MAC
include stdio.h include sys types.h include sys param.h include sys ioctl.h include sys socket.h include net if.h include netinet in h include net if ...
Android開發之獲取Mac位址的相容方法
隨著android的版本迭代,獲取裝置資訊的方法也可能發生改變,在android 6生效的方法,在android 8可能已經不生效了。諸如此類,獲取mac位址的方法也發生了變化。這裡找到了最新的適配方案 適配當前的最新版本android 9.0 並且記錄了整個適配的修復過程,以供參考。1 必須的許可...
Android開發 建立與獲取Assets目錄
先建立乙個檔案,位於編譯後的 class 檔案目錄。然後再把該檔案的絕對路徑做擷取,便能得到專案在電腦上的絕對路徑 每個專案在電腦上路徑都不一樣 再拼接上 src main assets 便能實現 assets目錄json檔案的建立了。private final static string outp...