
是否有一個命令,在輸入時輸出如下資訊:
- 如果網路連線是有線或無線
- 如果是無線網絡,則無線網路的名稱
- 訊號有多強
答案1
只需輸入終端“iw”,然後按Tab,您就會看到類似
iw iw iwconfig iwevent iwgetid iwlist iwpriv iwspy
所有與無線互聯網相關的內容,嘗試iwconfig
顯示有關信號和網路介面的統計資訊。
答案2
您可以將其作為第一個問題的 shell 腳本:
#!/bin/bash
if ! /bin/ip route | grep -q ^default; then
echo "No Internet connection"
echo
exit 0
fi
if="$(/bin/ip route |
awk '$1 == "default" {for (i=2;i<=NF;i++) if ($i == "dev") { i++;print $i; exit}}')"
if [ -z "$if" -o \! -e /sys/class/net/"$if" ]; then
echo "Sorry, some error, aborting."
echo
exit 1
fi
if /usr/sbin/iw dev "$if" info &>/dev/null; then
echo "The Internet connection is wireless."
echo
# uncomment the next line to start iwconfig
# iwconfig
else
echo "The Internet connection is wired."
echo
fi
您可以將其儲存為例如 ~/scripts/gatewayinfo.sh,使其可執行,chmod a+x ~/scripts/gatewayinfo.sh
並透過建立別名定義輕鬆呼叫它(例如~/.alias
):alias inetinfo="~/scripts/gatewayinfo.sh"