C 獲取本機IP位址和Mac位址的方法

2022-09-27 13:12:12 字數 613 閱讀 8399

查詢了幾個方法,經過除錯修改,下面這個方法能很好的獲取到本地的ip和mac位址。可以用於這方面的功能實現。主要是要新增system.management的引用。

using system;

using system.management;

using system.net;

public class program

//mac位址

mc = new managementclass("win32_networkadapterconfiguration");

managementobjectcollection moc = mc.getinstances();

foreach (managementobject mo in moc)

}//輸出

string outputstr = "ip:,\n m程式設計客棧ac位址:";

程式設計客棧outputstr = string.format程式設計客棧(outputstr, ip, mac);

console.writeline(outputstr);

} catch (exception e)

console.readline();

}}本文位址:

通過vbs獲取本機IP位址和MAC位址

1,定義函式 function getipmac computername dim objwmiservice,colitems,objitem,objaddress set objwmiservice getobject winmgmts computername root cimv2 set c...

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

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

C 獲取本機MAC位址

static void main string args private static string getmac moc null mc null return mac catch 另外,需要說明的就是乙個錯誤 問題 在c 程式設計中,已經在程式中已經新增了 using system.manage...