Skip to content

Instantly share code, notes, and snippets.

@markuswustenberg
Created November 10, 2009 17:38
Show Gist options
  • Save markuswustenberg/231068 to your computer and use it in GitHub Desktop.
Save markuswustenberg/231068 to your computer and use it in GitHub Desktop.
#!/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