2

While I working on a shell script, I need to display SSID,Passphrase,Encryption-type of connected wifi. I got SSID & Passphrase in output but I unable to display encryption-type.

Which command will work? I'm working on ubuntu 18.04. I want to print using cli..

Here I'm atteching output of nmcli device wifi list:

IN-USE  SSID                   MODE   CHAN  RATE        SIGNAL  BARS  SECURITY  
        CoreFragment           Infra  10    130 Mbit/s  75      ▂▄▆_  WPA1 WPA2 
        COMFAST                Infra  10    135 Mbit/s  69      ▂▄▆_  WPA1      
*       CoreFragment_5G        Infra  36    270 Mbit/s  69      ▂▄▆_  WPA1 WPA2 
        Yash Shah              Infra  10    270 Mbit/s  60      ▂▄▆_  WPA2      
        Appbirds_Technologies  Infra  11    270 Mbit/s  57      ▂▄▆_  WPA1 WPA2 
        dlink                  Infra  2     54 Mbit/s   49      ▂▄__  WEP       
        REDWING LABS_5G        Infra  149   270 Mbit/s  49      ▂▄__  WPA1 WPA2 
        REDWING LABS           Infra  4     130 Mbit/s  35      ▂▄__  WPA1 WPA2 
        20096641               Infra  11    65 Mbit/s   32      ▂▄__  --        
        LIFEKYOR PHARMA        Infra  6     270 Mbit/s  24      ▂___  WPA1 WPA2 
        Frankpro               Infra  11    270 Mbit/s  24      ▂___  WPA1     
6
  • encryption type like wpa-psk,wpa2,etc..
    – Yash Shah
    Jan 3, 2019 at 8:29
  • I just want to print encryption type only but I don't know from where I'll get it
    – Yash Shah
    Jan 3, 2019 at 8:38
  • Isn't it the last column in your output?
    – nohillside
    Jan 3, 2019 at 8:48
  • yes.. but I want to print using command
    – Yash Shah
    Jan 3, 2019 at 9:16
  • Try using iwconfig Jan 3, 2019 at 14:35

1 Answer 1

2

You can print the desired fields directly from nmcli, without the need for any other command.

From the manual:

-f | --fields {[field...] | all | common}
     This option is used to specify what fields (column names) should be printed. 

So, you can use:

nmcli -f SECURITY device wifi list

Consider using terse output with -t:

-t | --terse
     Output is terse. This mode is designed and suitable for computer (script) processing.
nmcli -t -f SECURITY device wifi list

To display only connected WIFI use something like this:

nmcli -t -f IN-USE,SECURITY device wifi list | grep '^\*' | colrm 1 2
1
  • 1
    It showing like: WPA1 WPA2 WPA1 WPA1 WPA2 WPA2 WPA1 WPA2 WEP WPA1 WPA2 WPA1 WPA2 but I want to display connected wifi only.
    – Yash Shah
    Jan 3, 2019 at 9:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .