獲取當前網絡卡的ip,mac等基本資訊

2021-10-06 19:13:31 字數 942 閱讀 6345

在多網絡卡環境下,我們怎麼來獲取自己當前使用的網絡卡資訊了?

通過判斷閘道器,因為多網絡卡一次也只能乙個網絡卡上網,能上網的網絡卡肯定存在閘道器

bool

getipandgateway

(std::string& strip, std::string& strmac, std::string& strgateway, std::string &strgatewaymac)if(

getadaptersinfo

(padapterinfo,

&uloutbuflen)

== no_error)

}else

if(padapterinfo)

free

(padapterinfo)

;getgatewaymac

(strgateway, strgatewaymac)

;return

true;}

void

getgatewaymac

(const std::string &strip, std::string &strmac);if

(0==memcmp

(pipnetrow[k]

.bphysaddr, bphysaddr, pipnetrow[k]

.dwphysaddrlen)

)continue

;//mac位址

for(

int j =

0; j < pipnetrow[k]

.dwphysaddrlen; j++

) strmac = szmac;

break;}

}}if(pipnettable)

free

(pipnettable)

;}

參考部落格:

前端獲取當前網域名稱,url等資訊

1,設定或獲取物件指定的檔名或路徑 window.location.pathname 2,設定或獲取整個 url 為字串 window.location.href 3,設定或獲取與 url 關聯的埠號碼 window.location.port 4,設定或獲取 url 的協議部分 window.lo...

linux中從檔案獲取當前網絡卡的工作模式

copy by duanjigang from source code of ethtool 6 struct ethtool cmd int get settings const char devname ecmd.cmd 1 ifr.ifr data caddr t ecmd if ioctl ...

SQL獲取當前時間 年 月 日等

sql select now 結果 2018 04 10 14 21 39 2 獲取當前時間年份 sql select year now 結果 2018 1 獲取上一年 sql select year now 1 結果 2017 獲取其餘年份,同上 3 獲取當前時間年份及當前該年第幾周 sql se...