linux 命令行使用 wifi

命令都可简写,例如:nmcli device status 可以简写成 nmcli d s

网卡状态

$ nmcli device status
DEVICE             TYPE      STATE         CONNECTION 
enp0s3             ethernet  connected     enp0s3     
wlp0s11u1          wifi      disconnected  --         
p2p-dev-wlp0s11u1  wifi-p2p  disconnected  --         
lo                 loopback  unmanaged     --

无线列表

$ nmcli -p device wifi list [ifname wlan0]
==============================
  Wi-Fi scan list (wlp0s11u1)
==============================
IN-USE  SSID                        MODE   CHAN  RATE        SIGNAL  BARS  SECURITY  
--------------------------------------------------------------------------------------------------------------
        ChinaNet-vh4h               Infra  6     130 Mbit/s  84      ▂▄▆█  WPA1 WPA2 
        ChinaNet-hxeh               Infra  8     130 Mbit/s  84      ▂▄▆█  WPA1      
        kefu                        Infra  1     135 Mbit/s  74      ▂▄▆_  WPA1 WPA2 
        TP-LINK_chen                Infra  6     405 Mbit/s  74      ▂▄▆_  WPA1 WPA2

连接网络

$ sudo nmcli -w 10 device wifi connect <SSID>  password <PASSWORD>

断开网络

$ sudo nmcli device disconnect