Created
November 10, 2009 17:38
-
-
Save markuswustenberg/231068 to your computer and use it in GitHub Desktop.
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/perl | |
# | |
# Uses libwww-perl and libcrypt-ssleay-perl | |
# | |
# A little script I made in Perl to update GratisDNS dynamic DNS (www.gratisdns.dk). | |
# | |
# Usage: | |
# ddns.pl -u username -p password -d domain -h hostname [-i IP] | |
use Switch; | |
use Getopt::Std; | |
use LWP::UserAgent; | |
my $ua = LWP::UserAgent->new(); | |
$ua->timeout(10); | |
my %opts; | |
getopts('u:p:d:h:i:', \%opts); | |
if (keys(%opts) < 4) | |
{ | |
die "Usage: ddns.pl -u username -p password -d domain -h hostname [-i IP]\n"; | |
} | |
my $url = 'https://ssl.gratisdns.dk/ddns.phtml?' . 'u=' . $opts{'u'} . '&p=' . $opts{'p'} . '&d=' . $opts{'d'} . '&h=' . $opts{'h'}; | |
if (defined $opts{'i'}) | |
{ | |
$url .= '&i=' . $opts{'i'}; | |
} | |
my $response = $ua->get($url); | |
if ($response->is_success) | |
{ | |
switch ($response->content) | |
{ | |
case /eksistere ikke/ | |
{ | |
print "Wrong username. Check your username and try again.\n"; | |
} | |
case /Fejl i kodeord/ | |
{ | |
print "Wrong password. Check your password and try again.\n"; | |
} | |
case /kan IKKE administreres af bruger/ | |
{ | |
print "This domain cannot be administered by this user. Check your domain name and try again.\n"; | |
} | |
case /Hostnavn er ulovligt/ | |
{ | |
print "Hostname is illegal. Check your hostname and try again.\n"; | |
} | |
case /A record findes ikke/ | |
{ | |
print "This hostname (A record) doesn't exist. Check your hostname and try again.\n"; | |
} | |
case /forvejen/ | |
{ | |
print "Already updated.\n"; | |
} | |
case /OK/ | |
{ | |
print "Hostname updated OK.\n"; | |
} | |
else | |
{ | |
print "Unknown error.\n"; | |
} | |
} | |
} | |
else | |
{ | |
die $response->status_line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment