獲取指定IP的終端的MAC位址

2021-03-31 19:38:30 字數 674 閱讀 1032

因為業務需要,需要給公司部分終端進行登記,以保證授權終端能夠登入業務系統,最好的方法就是記錄下每台終端的mac位址來進行驗證是否有授權。

[dllimport("iphlpapi.dll")]

public static extern int sendarp(int32 dest, int32 host, ref int64 mac, ref int32 length);

//dest為目標機器的ip;host為本機器的ip

[dllimport("ws2_32.dll")]

public static extern int32 i***_addr(string ip);

public static string get***cardaddress(string strip)

catch(exception error)

}在上面的方式使用一段時間之後發現只能獲取到同一網段或沒有經過任何路由的終端的mac位址,而對那些不同網段或經過了路由的終端的mac位址則無法正常獲取到mac位址。下面的作業系統命令方式可以解決此問題:

public static string get***cardaddress2(string strip)

process.waitforexit();

return mac.replace("-", "").trim();

}

獲取指定網絡卡的MAC位址

由於終端裝置多網絡卡使用的問題,以前使用netbios 獲取網絡卡mac位址的方法可能導致不可靠的問題。現推薦大家使用如下方法實現 cstring getlicense cstring strmac cstring getmacbyname cstring strname strcat szfile...

如何獲取mac的ip位址

一.命令列方式 1.開啟命令列 2.輸入輸入命令 ifconfig en0 3.回車,即可 en0 flags 8863mtu 1500options 400ether 90 9c 4a b7 4b f6 inet6 fe80 1044 95dd 82db 56de en0 prefixlen 64...

Qt獲取本機的ip位址 MAC位址

qstring gethostipaddress 如果沒有找到,則以本地ip位址為ip if stripaddress.isempty stripaddress qhostaddress qhostaddress localhost tostring return stripaddress qstr...