use strict;
use Time::Local;
use Net::Telnet();
open(OUTPUT,">output.txt");
print "****THIS SCRIPT IS DEVELOPED BY KUMARMANTRI****\n";
print "FORMAT TO RUN THIS SCRIPT===rssi.pl apip suip HOURS INTERVAL\n";
sub tel
{
my ($ip,$s)=@_;
my $t=Net::Telnet->new(Host=>$ip,Prompt=>'/login: /',Timeout=>7)or print OUTPUT "couldn't telnet\n";
$t->cmd(String=> "admin",Prompt=>'/password: /');
$t->cmd(String=> "admin",Prompt=>'/> /');
$t->cmd(String=>'login',Prompt=>'/# /');
my @output=$t->cmd(String=>$s,Prompt=>'/# /');
return(@output);
$t->close;
}
my $count=($ARGV[2]*60)/$ARGV[3];
my $i=$count;
while($i>0)
{
my @ap=($ARGV[0],"wlanconfig ath0 list");
my @su=($ARGV[1],'iwconfig ath0');
###################
my @apsignal=tel(@ap);
chomp($apsignal[1]);
my @rssi=split(/ /,$apsignal[1]);
###################
my @susignal=tel(@su);
chomp($susignal[5]);
my @rss=split(/=/,$susignal[5]);
###################
my $time=scalar localtime;
print "$time\t APRSSI($ap[0]) $rssi[11] SURSSI($su[0]) $rss[2]\n";
print OUTPUT "$time\t APRSSI($ap[0]) $rssi[11] SURSSI($su[0]) $rss[2]\n";
my $second=$ARGV[3]*60;
sleep ($second);
$i--;
}
close(OUTPUT);
Recently i needed to work on a script which monitors the signal status of a wireless link, if you gone through my earlier scripts and compares this one with those you find this one some little bit advanced than those...the reason is because i thought myself kind of like a very beginner of perl so i decided to learn advanced and reduce the code.
here my main focus is explain the passing of arguments to a perl scripts,i designed this in such a way that while running this program itself you can give the inputs.
For example:rssi.pl 10.0.0.1 10.0.0.2 1 5
here the rssi.pl is name of the script and 10.0.0.1, 10.0.0.2,1 and 5 are the inputs..so to make use of this you have to include the $ARGV in your code depends on the inputs you need,here i make use of 4 inputs so included all those 4 inputs in my code as $ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3]
I hope you understand the code and use of arguments, please leave a comment if you have any doubts and suggest any ideas.
oops i forgot to tell you the use of this script, this code captures the rssi of both AP and SU for a particular time with an interval specified by the user.
usage: rssi.pl 10.0.0.1(ap ip) 10.0.0.2(su ip) 1(timeperiod to run in hours) 5(interval in minutes)
use Time::Local;
use Net::Telnet();
open(OUTPUT,">output.txt");
print "****THIS SCRIPT IS DEVELOPED BY KUMARMANTRI****\n";
print "FORMAT TO RUN THIS SCRIPT===rssi.pl apip suip HOURS INTERVAL\n";
sub tel
{
my ($ip,$s)=@_;
my $t=Net::Telnet->new(Host=>$ip,Prompt=>'/login: /',Timeout=>7)or print OUTPUT "couldn't telnet\n";
$t->cmd(String=> "admin",Prompt=>'/password: /');
$t->cmd(String=> "admin",Prompt=>'/> /');
$t->cmd(String=>'login',Prompt=>'/# /');
my @output=$t->cmd(String=>$s,Prompt=>'/# /');
return(@output);
$t->close;
}
my $count=($ARGV[2]*60)/$ARGV[3];
my $i=$count;
while($i>0)
{
my @ap=($ARGV[0],"wlanconfig ath0 list");
my @su=($ARGV[1],'iwconfig ath0');
###################
my @apsignal=tel(@ap);
chomp($apsignal[1]);
my @rssi=split(/ /,$apsignal[1]);
###################
my @susignal=tel(@su);
chomp($susignal[5]);
my @rss=split(/=/,$susignal[5]);
###################
my $time=scalar localtime;
print "$time\t APRSSI($ap[0]) $rssi[11] SURSSI($su[0]) $rss[2]\n";
print OUTPUT "$time\t APRSSI($ap[0]) $rssi[11] SURSSI($su[0]) $rss[2]\n";
my $second=$ARGV[3]*60;
sleep ($second);
$i--;
}
close(OUTPUT);
Recently i needed to work on a script which monitors the signal status of a wireless link, if you gone through my earlier scripts and compares this one with those you find this one some little bit advanced than those...the reason is because i thought myself kind of like a very beginner of perl so i decided to learn advanced and reduce the code.
here my main focus is explain the passing of arguments to a perl scripts,i designed this in such a way that while running this program itself you can give the inputs.
For example:rssi.pl 10.0.0.1 10.0.0.2 1 5
here the rssi.pl is name of the script and 10.0.0.1, 10.0.0.2,1 and 5 are the inputs..so to make use of this you have to include the $ARGV in your code depends on the inputs you need,here i make use of 4 inputs so included all those 4 inputs in my code as $ARGV[0],$ARGV[1],$ARGV[2],$ARGV[3]
I hope you understand the code and use of arguments, please leave a comment if you have any doubts and suggest any ideas.
oops i forgot to tell you the use of this script, this code captures the rssi of both AP and SU for a particular time with an interval specified by the user.
usage: rssi.pl 10.0.0.1(ap ip) 10.0.0.2(su ip) 1(timeperiod to run in hours) 5(interval in minutes)
No comments:
Post a Comment