#!/usr/bin/perl -w # sudo apt-get install 9menu ifupdown wireless-tools $dev = shift || 'wlan0'; $SIG{__DIE__} = sub { $msg = join '', @_; chomp $msg; exec qw(9menu -popup -label), 'Choose a network', "$msg:exit"; }; %iwlist = grep defined, map { m{ ESSID:"([^"]+)" .* Encryption\ key:off .* Quality=(\d+)/(\d+) }xs ? ($1, $3 ? $2/$3 : 0) : undef } split /^\s+Cell \d+ - /m, qx(/sbin/iwlist wlan0 scan); die "no unencrypted networks found\n" unless %iwlist; @iwlist = sort { $iwlist{$a} <=> $iwlist{$b} || $a cmp $b } keys %iwlist; printf "[%.2f] $_\n", $iwlist{$_} for @iwlist; sub ifup { $essid = shift; qq(iwconfig $dev essid "$essid" commit; ifup --force $dev) } exec '9menu', '-label', 'Choose a network', map { "$_:exec ".ifup($_) } @iwlist;