G
giraffe6044
I was given this perl script as a example of a program to control our
remote powerdevices. Problem is i do not know Perl. I am creating the
site in Coldfusion
Can someone help explain to me what this script is doing to get the
STATUS of the RPS.
is it a form post? or is it requesting a URL and if so what URL.
here is the device.
http://www.digital-loggers.com/EPC.html
Thank you very much for any help
#!/usr/bin/perl -w
#----------------------------------------------------------------------
use LWP::UserAgent;
#----------------------------------------------------------------------
$ua = LWP::UserAgent->new();
#----------------------------------------------------------------------
if ($#ARGV <= 1)
{
print STDERR 'Usage: UserUtil <Host>[
ort] <login
assword>
<[n]{on|off|pulse|status}> ...'."\n";
exit -1;
}
($epc, $auth)=splice(@ARGV,0,2);
$base='http://'.$auth.'@'.$epc.'/';
foreach (@ARGV)
{
$_=lc;
s/(^[^1-8])/a$1/;
if (/^([1-8a])on$/)
{
RelLink('outleton?'.$1);
}
elsif (/^([1-8a])off$/)
{
RelLink('outletoff?'.$1);
}
elsif (/^([1-8a])pulse$/)
{
RelLink('outletgl?'.$1);
}
elsif (/^([1-8a])status$/)
{
$n=$1;
defined($response) && ($response->content =~/<a href=outleto/) ||
RelLink('');
$content=$response->content;
while ($content =~ /<a href=outlet(on|off)\?([1-8])>/ig)
{
if (($2 eq $n) || ($n eq 'a'))
{
if ($1 eq "on")
{print $2," OFF\n";}
else
{print $2," ON\n";}
}
}
}
else
{
die "Unknown command $_\n";
}
}
sub RelLink
{
local ($_) = @_;
#print STDERR $base.$_,"\n";
$response = $ua->get($base.$_);
$response->is_error() && die $response->status_line;
}
remote powerdevices. Problem is i do not know Perl. I am creating the
site in Coldfusion
Can someone help explain to me what this script is doing to get the
STATUS of the RPS.
is it a form post? or is it requesting a URL and if so what URL.
here is the device.
http://www.digital-loggers.com/EPC.html
Thank you very much for any help
#!/usr/bin/perl -w
#----------------------------------------------------------------------
use LWP::UserAgent;
#----------------------------------------------------------------------
$ua = LWP::UserAgent->new();
#----------------------------------------------------------------------
if ($#ARGV <= 1)
{
print STDERR 'Usage: UserUtil <Host>[
<[n]{on|off|pulse|status}> ...'."\n";
exit -1;
}
($epc, $auth)=splice(@ARGV,0,2);
$base='http://'.$auth.'@'.$epc.'/';
foreach (@ARGV)
{
$_=lc;
s/(^[^1-8])/a$1/;
if (/^([1-8a])on$/)
{
RelLink('outleton?'.$1);
}
elsif (/^([1-8a])off$/)
{
RelLink('outletoff?'.$1);
}
elsif (/^([1-8a])pulse$/)
{
RelLink('outletgl?'.$1);
}
elsif (/^([1-8a])status$/)
{
$n=$1;
defined($response) && ($response->content =~/<a href=outleto/) ||
RelLink('');
$content=$response->content;
while ($content =~ /<a href=outlet(on|off)\?([1-8])>/ig)
{
if (($2 eq $n) || ($n eq 'a'))
{
if ($1 eq "on")
{print $2," OFF\n";}
else
{print $2," ON\n";}
}
}
}
else
{
die "Unknown command $_\n";
}
}
sub RelLink
{
local ($_) = @_;
#print STDERR $base.$_,"\n";
$response = $ua->get($base.$_);
$response->is_error() && die $response->status_line;
}