bashスクリプトを使用して、ワイヤレスインターフェイスが稼働しているかどうかを確認しようとしています。すべてのインターフェースの /proc/net/wireless の Status フィールドをチェックすることで、これを行うことができると思います。ただし、そのフィールドで可能な値とその意味への参照を探してみましたが、何も出てこないようです。誰か知っていますか?これは、この問題に取り組む理想的な方法ですか?
2356 次
1 に答える
2
operstate
各インターフェイスのをチェックして、どちらかであるかどうかを確認する必要があります。上、下、または不明。使用する1つの方法は次の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
ワイヤレスインターフェイスのみをチェックするには、各インターフェイスの下にある「wireless」というフォルダをチェックする必要があります。を使用する1つの方法があり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.
于 2012-10-09T02:06:12.177 に答える