How to Detect Security Mode of Wifi Access Point? (WEP/WPA/WPA2)

Solution 1:

You can use the iwlist tool to print out all details of access points nearby. Assuming your wireless device is called wlan0:

sudo iwlist wlan0 scan

The output from iwlist will show each 'Cell' (or access point) that it finds, including the following details about the encryption type:

                    IE: IEEE 802.11i/WPA2 Version 1
                    Group Cipher : TKIP
                    Pairwise Ciphers (2) : CCMP TKIP
                    Authentication Suites (1) : PSK

This indicates that a network near me is using WPA2, using a pre-shared key (PSK).

Solution 2:

nmcli is command-line client for NetworkManager. It can be used to view security types of nearby wireless access points.

$> nmcli device wifi list 

Result will show up as following:

result image

Solution 3:

NetworkManager has a great command-line backend called nmcli. The small draw-back is that some commands in 15.04 differ from 14.04 version of nmcli.

Ubuntu 14.04

nmcli -f NAME con status allows listing names of the current connections. For example,

$ nmcli -f NAME,DEVICES con status                                                                                                
NAME                      DEVICES   
Serg-Wifi                    wlan0 

Now, to list specific details about a connection, we can do nmcli con list id "WifiName". To be more specific, we are looking for line that says key-mgmt.

$ nmcli con list id "SergWifi" | awk '/key-mgmt/ {print $2}'                                                                        
wpa-psk

Thus we know , this wifi uses WPA protection.

Another hint is the following line:

802-11-wireless.security:               802-11-wireless-security

Now, how do we put this into the same script ? If you have only one connection established ,

nmcli con list id "$(nmcli -t -f NAME con status)" | awk '/key-mgmt/||/802-11-wireless\.security/ {print $2}'

Here we merely manipulate nmcli with -t flag to give us only the name of wifi Access Point without the pretty header,and use it in parameter substitution brackets$( . . .) and give it as an input to nmcli con list id to list data about that Access Point. Finally, awk just filters out the necessary line.

If you have wifi connection established but also Ethernet connected, nmcli -f NAME con status will output multiple lines. I suggest filtering out wifi from that list, with nmcli -f NAME,DEVICES con status | awk '/wlan0/ {print $1}'. The rest of the processing would be the same as above.

Ubuntu 15.04

The above commands translate in 15.04 as follows:

  • nmcli -t -f NAME,DEVICE con status | awk -F':' '/wlan0/{print }' to get the name of established connection on wlan0
  • nmcli con show "ConnectionName" to list details about your established connection.

Side note: in Ubuntu 14.04 there is nm-tool which lists information about your current connections in a readily organized format, however it is not present in 15.04 , hence I suggest you study and play with it on your own