Skip to content

Instantly share code, notes, and snippets.

@typhonius
Created August 17, 2013 06:37
Show Gist options
  • Save typhonius/6255593 to your computer and use it in GitHub Desktop.
Save typhonius/6255593 to your computer and use it in GitHub Desktop.
A small script that gets the current IP and updates a domain using the API for badger.com Currently the domain ID is hard coded although work will be done to allow iteration and ID lookup
use strict;
use warnings;
use HTTP::Request;
use LWP::UserAgent;
use Regexp::Common qw /net/;
use JSON;
my $email = 'FILLME';
my $password = 'FILLME';
my $badger = 'https://api.badger.com';
my $params = '/domains/:DOMAIN/records/:RECORD_ID';
my $ua = LWP::UserAgent->new;
# Get the current external IP according to checkip.dyndns.org
my $ipreq = HTTP::Request->new(GET => 'http://checkip.dyndns.org');
my $ipres = $ua->request($ipreq);
my $ip = '';
if ($ipres->is_success) {
if ($ipres->content =~ /$RE{net}{IPv4}{-keep}/) {
$ip = $1;
$params .= '?content=' . $ip;
}
}
else {
die ($ipres->content);
}
my $req = HTTP::Request->new(PUT => $badger . $params);
$req->authorization_basic($email, $password);
$req->header('Content-Length' => 0);
my $res = $ua->request($req);
if ($res->is_success) {
print $res->content;
}
else {
die ($res->content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment