Hi,
I wrote a little script for sed that takes a wireless scan output and prints in human readable form the essid and the MAC address. It's useful when you have a lot of wifis around you to identify each other easily, and for the case I'm using it: connect only to desired hosts from a file with the same format as the output.
Basically, this sed script outputs something like this:
[essid1]
Address=00:E4:55:66:16:71
[essid2 with spaces available]
Address=00:E4:55:66:16:72
[essid2-whatever]
Address=00:E4:55:66:16:73
[]
Address=00:E4:55:66:16:71
As you can see it works with ESSID:"" too. Enough talk, here are these lines:
#
# Copyright (c) 2010 Sebastián Treu.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Author:
# Sebastian Treu
# sebastian.treu (at) gmail.com
#
#!/bin/bash
sed -n '
'/ESSID/' !{
'/Cell/' !{
d
}
'/Cell/' {
s/^[ ]*//g
s/Cell [0-9]\+ - Address: /Address=/g
x
d
}
}
'/ESSID/' {
s/^[ ]*//g
s/ESSID:\"\(.*\)\"/[\1]/g
p
x
p
}'
For example, if you want to use it you can issue this line:
$ iwlist wlan0 scan | ./parse-output.sh
Note: wlan0 is your capable scanning device. It's posible that if your device does not have the scanning ability, then iwlist will output an error lik:
eth0 Interface doesn't support scanning.
As the script reads from the standard input, that it's not parsed. That message doesn't came from stdin. Remember also that some distros prohibits from a normal user to do a scan.
I hope this can be useful to anyone, don't forget to make a comment if you found something wrong with it! Thanks.
