Friday, 5 February 2016

Scan WiFi networks on the raspberry pi using essid and the grep command

First of all, find the name of the wireless network adapter. Enter the command ifconfig to show each network interface along with its details. The IP address and further information is also shown, but we just need the name shown in the left most column. There will be an entry for lo, and probabaly one for eth0 if you have a connection by ethernet also. My WiFi dongle showed up as wlan0 which is typical. If you have more than one WiFi adapter, it will probabaly show up as wlan1, wlan2, etc.

Then use the following command:

sudo iwlist wlan0 scan

I have used wlan0 as the interface name, if you found something earlier in a previous step then obviously you should change wlan0 to the interface name.

I ended up getting quite a log list of networks which went off the top of the screen, with a lot of unneeded information. So it is possible to reduce the amount of information shown. To do that, we pipe the output to the grep command, which searches within the data and only displays data that matches what we are searching for. Each network contains information about the network, including the field "ESSID" which is the network ID. To only display these lines, use the following command:

sudo iwlist wlan0 scan | grep ESSID

The command is case sensitive, alternatively we can use the -i flag at the end to make it case insensitive, as follows:

sudo iwlist wlan0 scan | grep essid -i

No comments:

Post a Comment