我試圖用bash腳本檢查是否有無線接口。我想我可以通過檢查/ proc/net/wireless中的Status字段來查看每個接口。然而,我試圖尋找這個領域可能的價值觀及其含義,並且似乎沒有出現。有人知道嗎?這是解決這個問題的理想方式嗎?/proc/net/wireless中的「Status」字段
1
A
回答
1
您需要檢查每個接口的operstate
以確定它是否是;向上,向下或未知。下面是使用GNU awk
一個辦法:
awk '{ split(FILENAME, array, "/"); print array[5] ": " $1 }' $(find /sys/class/net/*/operstate ! -type d)
在我的系統,這裏的一些結果:
eth0: up
lo: unknown
vboxnet0: down
wlan0: up
要檢查無線接口只,你將需要檢查一個名爲「無線」文件夾在每個界面下。以下是使用GNU awk
的一種方法。
awk -F "/" 'FNR==NR { wire[$5]++; next } { split(FILENAME, state, "/"); if (state[5] in wire && $1 == "up") print state[5] }' <(find /sys/class/net/*/wireless -type d) $(find /sys/class/net/*/operstate ! -type d)
結果:
wlan0
僞代碼:
1. Get the directory names of the wireless devices as the 1st argument
2. Split these names on the "/" delimiter
3. Add the 5th column (the name of the wireless device) to an array called 'wire'
4. Now read in the operstates of all network interfaces as the 2nd argument
5. Split the interface filenames on the "/" delimiter to an array called 'state'
6. If the interface is a wireless interface (i.e. if it's in the array called
wire) and its operstate is "up", print it.
+0
謝謝。這似乎是朝着正確方向邁出的一步。但是,第二個和第三個awk語句是否僅返回依賴於以「wlan」開頭的所有無線接口的名稱的無線接口?在很多情況下很可能會出現這種情況,對吧? –
+0
@timtran:我刪除了第二個和第三個awk語句,因爲無線接口可能會用奇怪的字符命名。在我的測試中,我發現每個無線接口都應該包含一個名爲「無線」的目錄。上面編輯的代碼檢查這一點,只在無線接口名稱爲「up」時才返回。請參閱僞代碼。 HTH。 – Steve
相關問題
- 1. /proc/<pid> status sigign字段
- 2. 在NodeWebkit中的XMLHttpRequest,status = 0
- 3. 'show table status'中的Data_length
- 4. exit_group(int status)linux調用中的「status」參數是什麼?
- 5. svn status in TortoiseSVN?
- 6. Btrieve GetNextExtended Status 62
- 7. readyState vs status == 200
- 8. IFERROR STATUS WITHIN VLOOKUP
- 9. Facebook Wall Status
- 10. jomsocial force status refresh
- 11. 解析git-status
- 12. RabbitMQ Federation Status econnrefused
- 13. Subversion:Query Sparse Checkout Status
- 14. paypal status is pending
- 15. Steam set user status
- 16. jsp中的HTTP Status 404錯誤,netbeans
- 17. `git的status`和EOL檢測
- 18. err ['status']是做什麼的?
- 19. 'git status'命令的對面
- 20. PHP echo $ result'{「status」:「success」}';
- 21. rdlc CountDistinct where status = 1
- 22. subversion status -u到diff
- 23. status代碼爲Alamofire4
- 24. Orchard CMS Warmup Status Zero
- 25. Heroku code = H10 status = 503
- 26. Laravel 4 localhost status 500
- 27. Oauth Consumer - LinkedIN UPDATE STATUS
- 28. WWW.responseHeader [「STATUS」]不存在
- 29. paypal API doExpressCheckoutPayment status Pending
- 30. Docker swarm manager pending status
我不是太熟悉的無線接口,但不能使用'ifconfig'或'iwconfig'和grep爲UP還是什麼? – DanielGibbs