Created
February 23, 2015 02:51
-
-
Save und3f/83e7932ab9570d46ea98 to your computer and use it in GitHub Desktop.
Asianet broadbend pinger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Asianet Broadband automatical pinger | |
# Copyright (c) 2015, Sergii Zasenko | |
use strict; | |
use warnings; | |
$| = 1; | |
use LWP::UserAgent; | |
use HTTP::Request; | |
use IO::Interface::Simple; | |
my $interval = 300; | |
my ($username, $password) = @ARGV or | |
die "usage: $0 <username> <password>"; | |
my $ua = LWP::UserAgent->new; | |
$ua->ssl_opts(verify_hostname => 0); | |
my $if_wlan0 = IO::Interface::Simple->new('wlan0'); | |
$ua->local_address($if_wlan0->address); | |
my $res = $ua->post( | |
"https://mwcp-spg-01a.adlkerala.com:8003/index.php" => { | |
auth_user => $username, | |
auth_pass => $password, | |
redirurl => '$PORTAL_REDIRURL$', | |
accept => 'Login >>' | |
} | |
); | |
die 'Failed to login' | |
unless $res->decoded_content =~m(You have successfully logged in); | |
print "Logged in. Pinging…"; | |
while (sleep($interval)) { | |
my $ping_res = $ua->post("https://mwcp-spg-01a.adlkerala.com:8003/" => | |
{alive => 'y', auth_user => $username}); | |
die $ping_res->status_line unless $ping_res->is_success; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment