linux 判斷網絡卡型別 有線 無線

2021-10-14 16:44:11 字數 4230 閱讀 1713

檢視所有網路介面

ls /sys/class/net/

要區分無線網絡卡則可以在

/sys/class/net/$/

下面找 phy80211 或者 wireless 資料夾,無線網絡卡目錄下才存在這些資料夾

通過c函式來檢視:

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

int device_get_hwinfo(int fd, char* ifname)

return ifr.ifr_hwaddr.sa_family; //this valueint main(int argc, char* ar**)

if_type = device_get_hwinfo(fd, if_name);

printf("%s type is %d\n", if_name, if_type);

return 0;得到網絡卡列表:

#include

#include

#include

#include

#include

int get_if_name(char ifstr[32])

for (i = if_ni; ! (i->if_index == 0 && i->if_name == null); i++)

else

printf("%u: %s\n", i->if_index, i->if_name);

}if_freenameindex(if_ni);

return num;int if_is_wlif(const char * ifname)

for (i = if_ni; ! (i->if_index == 0 && i->if_name == null); i++)

printf("%u: %s\n", i->if_index, i->if_name);

if_freenameindex(if_ni);*/

exit(exit_success);

}檢視裝置下的網絡卡可以通過篩選型別值來判斷網絡卡型別

cat /sys/class/net/eth0/type

1網絡卡型別的值是 1

無線網絡卡 managed和 master模式的值也是 1,當是 monitor模式時值才為 802 或 803

裝置型別值列表:

/* dummy types for non arp hardware /

#define arphrd_slip 256

#define arphrd_cslip 257

#define arphrd_slip6 258

#define arphrd_cslip6 259

#define arphrd_rsrvd 260 / notional kiss type /

#define arphrd_adapt 264

#define arphrd_rose 270

#define arphrd_x25 271 / ccitt x.25 /

#define arphrd_hwx25 272 / boards with x.25 in firmware /

#define arphrd_can 280 / controller area network /

#define arphrd_ppp 512

#define arphrd_cisco 513 / cisco hdlc /

#define arphrd_hdlc arphrd_cisco

#define arphrd_lapb 516 / lapb /

#define arphrd_ddcmp 517 / digital』s ddcmp protocol /

#define arphrd_rawhdlc 518 / raw hdlc */

#define arphrd_tunnel 768 /* ipip tunnel /

#define arphrd_tunnel6 769 / ip6ip6 tunnel /

#define arphrd_frad 770 / frame relay access device /

#define arphrd_skip 771 / skip vif /

#define arphrd_loopback 772 / loopback device /

#define arphrd_localtlk 773 / localtalk device /

#define arphrd_fddi 774 / fiber distributed data inte***ce /

#define arphrd_bif 775 / ap1000 bif /

#define arphrd_sit 776 / sit0 device - ipv6-in-ipv4 /

#define arphrd_ipddp 777 / ip over ddp tunneller /

#define arphrd_ipgre 778 / gre over ip /

#define arphrd_pimreg 779 / pimsm register inte***ce /

#define arphrd_hippi 780 / high performance parallel inte***ce /

#define arphrd_ash 781 / nexus 64mbps ash /

#define arphrd_econet 782 / acorn econet /

#define arphrd_irda 783 / linux-irda /

/ arp works differently on different fc media … so /

#define arphrd_fcpp 784 / point to point fibrechannel /

#define arphrd_fcal 785 / fibrechannel arbitrated loop /

#define arphrd_fcpl 786 / fibrechannel public loop /

#define arphrd_fcfabric 787 / fibrechannel fabric /

/ 787->799 reserved for fibrechannel media types /

#define arphrd_ieee802_tr 800 / magic type ident for tr /

#define arphrd_ieee80211 801 / ieee 802.11 /

#define arphrd_ieee80211_prism 802 / ieee 802.11 + prism2 header /

#define arphrd_ieee80211_radiotap 803 / ieee 802.11 + radiotap header */

#define arphrd_ieee802154 804

#define arphrd_phonet 820 /* phonet media type /

#define arphrd_phonet_pipe 821 / phonet pipe header /

#define arphrd_caif 822 / caif media type */

#define arphrd_void 0xffff /* void type, nothing is known /

#define arphrd_none 0xfffe / zero header length */

/* arp protocol opcodes. /

#define arpop_request 1 / arp request /

#define arpop_reply 2 / arp reply /

#define arpop_rrequest 3 / rarp request /

#define arpop_rreply 4 / rarp reply /

#define arpop_inrequest 8 / inarp request /

#define arpop_inreply 9 / inarp reply /

#define arpop_nak 10 / (atm)arp nak */

vc 禁用無線網絡卡 禁用網絡卡 禁用有線網絡卡

首先和普通的方法一樣,根據guid禁用網絡卡類裝置,只是在禁用時列舉第i塊網絡卡,讀取其裝置資訊,讀到有 wireless 這個串的就認為它是無線網絡卡,就對它使用禁用操作,否則就接著列舉第i 1塊網絡卡,直到都列舉完.下面給出重要結構.drivedemodlg.cpp implementation...

ubuntu 同時使用無線網絡卡和有線網絡卡

有線連線雷射 無線上外網,sudo route add default gw 30.10.208.1 用處就是上網用外網,pt,印表機,內網windows機器啥的用內網,互不干涉 原來可以這麼簡單 1.有線,無線都連上 ifconfig eth0 eth1 一般來說 eth0 對應有線網絡卡,eth...

電腦無線網絡卡和有線網絡卡同時使用

一 概述 1 需要 由於筆者的無線聯網比有線的速度快,所以連線網際網路要用無線網絡卡。我的虛擬機器橋接與主機溝通,所以需要有線網絡卡連線區域網。2 問題 如果同時連線有線網絡卡和無線網絡卡,因為有線網絡卡的優先順序較高,故僅有線區域網能正常工作,無線網絡卡可連線但卻無法傳送資料。為了讓無線網絡卡工作...