#!/usr/bin/perl -w use utf8; use strict; #subs here #scan - match all networks available inside ESSID:" " HERE #You`ll see HERE in quotted marks and you can select the network to #connect to that net sub scan { my $scanned = `iwlist scan`; my @nets = (); my @lines = split(/\n/, $scanned); foreach my $word (@lines) { my @words = split(/:/, $word); foreach my $pat ( @words ) { if ( $pat =~ m/"/i ) { print "Pattern found: $pat \n"; #optional message push(@nets, $pat); } } } return @nets; } #check connection sub check { my $con = `ping -c 1 yahoo.com`; my @match = split(/ /, $con); foreach (@match) { if ( $_ =~ m/ttl/i || $_ =~ m/rtt/i) { #find any ttl strings or rtt return 1; } } return 0; } #trims all quotes from the ESSID string sub trim { my @tr = @_; my @trimmed = split(/"/, $tr[0]); return @trimmed; } #connect to #you can connect to the net here sub connecd { my @conn = @_; print "If network has password enter it: "; chomp(my $pawd = ); print $conn[0], " you choose\n"; my $connection = &trim($conn[0]); if (system("iwconfig wlan0 essid $connection key s: $pawd" ) ) { return 1; } else { return 0; } } #PROMPT sub prompt { my @txt = @_; print $txt[0]; chomp(my $choice = ); return $choice; } #MENU sub menup { print <> "); if ( $choice eq "connectme" ) { print "Available networks.... \n"; &scan(); } elsif ( $choice eq "killme" ) { system("killall dhcpcd"); } elsif ( $choice eq "checkme" ) { if ( &check() ) { print "You are connected to the network\n"; } else { print "You are not connected \n"; } } else { print "Error! I don`t know what [ $choice ] means ..\n"; &menup(); } } ############################################################################### my (@options) = @ARGV; # do we use the right ones? if ( $options[0] eq "-s" ) { &menup(); } elsif ( $options[0] eq "-p" ) { #print to file } else { print "Error command!\nPLease use -s for scan or -p for print to file(WIP)\n"; }