#!/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 slice { #slices a string from given start position to end possition my ($from, $to) = ($_[1], $_[2]); my @sl = split(//, $_[0]); if ( $from <= $to ) { $_[0] = join("", @sl[$from..$to]); } elsif ( (! defined($_[1])) || (! defined($_[2])) ) { $_[0] = join("", @sl); } else { $_[0] = join("", @sl); } } sub scan { my $scanned = `iwlist scan`; my @nets=(); my $loop = 0; my @lines = split(/\n/, $scanned); foreach my $word (@lines) { my @words = split(/:/, $word); foreach my $pat ( @words ) { if ( $pat =~ m/"/i ) { #print "Network found: $pat \n"; #optional message $nets[$loop++] = $pat."\n"; } } } return @nets; #returns an array of networks... ??? } #end of SCAN #record output to file so you can load later sub record { my $path = "/home/"; my $user = prompt("Please, enter your home user name ( ex. john, supposed that it`s /home/john ). \n" ); $path .= $user; $path .= "/"; print "Your home dir is: $path \n"; print "Here will go the files recordyou are creating\n"; #correct ? Y/N later... my $fname = prompt("Name of the file?( no extensions needed)\n"); my $recname = $path . $fname; open (LOG, '>', $recname); my @inp = &scan(); print LOG @inp; close(LOG); } #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"; printf("%10s \n", &scan()); my $choice2 = &prompt(">> "); &connecd($choice2); } elsif ( $choice eq "killme" ) { system("killall dhcpcd"); } elsif ( $choice eq "checkme" ) { if ( &check() ) { print "Available networks are: \n"; print &scan(), "\n"; print "You are connected to the network\n"; } else { print "You are not connected \n"; } } elsif ( $choice eq "exitme" ) { print "Goodbye!\n"; } else { print "Error! I don`t know what [ $choice ] means ..\n"; &menup(); } } sub oscheck { my $pattern = ("iwlist scan"); if ( ! $pattern ) { print "You don`t have [ iwlist ] installed on your OS\n"; return 0; } else { return 1; } } ############################################################################### my (@options) = @ARGV; # do we use the right ones? if ( &oscheck() ) { if ( $options[0] eq "-s" ) { &menup(); } elsif ( $options[0] eq "-p" ) { &record(); } else { print "Error command!\nPLease use -s for scan or -p for print to file(WIP)\n"; } } else { print "Are we using LINX shell?\n"; }