Re: Dynamic DNS management
- From: Brian McCauley <nobull67@xxxxxxxxx>
- Date: 2 May 2007 10:41:56 -0700
On May 2, 12:42 am, Nooze Goy <nooze...@xxxxxxxxxxxx> wrote:
I'm in the process of setting up a web server - actually, it's pretty
much working, just a few irritating things lurking about, occasionally
leaping out and biting me on the arse.
One of the irritations is that with a dynamic DNS, I'm having to update
the IP addresses for the authoritative DNS server of multiple domains
hosted here. They're on one DNS service, ZoneEdit, and I found a couple
of pieces of code to update the IP addresses. One was ddclient, but
before I could get the config debugged, I tried another - which is not
so much a program as a command-line. It works okay, except that
ZoneEdit's server is agonizingly slow to respond, so it takes ten or
fifteen seconds to respond for each domain.
wget -O - --http-user=mylogin --http-passwd=myp455
'http://dynamic.zoneedit.com/auth/dynamic.html?host=my.domain.com'
In the script, the above line is repeated for each domain; each line
takes ten or fifteen seconds to process - doesn't seem reasonable, ***
hu nose?
Obviously, with five or six domains, you're going to be hard-pressed to
update the IP every minute,
Unless you spawn 5 or 6 wget commands at once.
and with 20 domains you're basically looking
at five solid minutes of updating anytime the ISP changes the IP, so it
doesn't make any sense to update unless it's actually changed.
I wrote a little Perl script to check the IP and log it and compare with
last time it checked, and do the update only if the two don't match.
It works fine right now - all it does is run a bash script of the
command-line entries shown above. But, of course, it's still sllooowwwww
as molasses.
I'm assuming that there's some rational way to have my perl prog connect
to the DNS update server directly,
There's Net::DNS if the server accepts standard DNS updates.
and maybe a) that'll be faster
That's a question about dynamic.zoneedit.com
or b)
there's some way to update all the domains in the list either with one
string
That is a question about the HTTP GET API presented at
http://dynamic.zoneedit.com/auth/dynamic.html
or in a loop.
A loop would be no faster.
So... here's the code - feel free to throw rocks at it, but it works...
(barring typos - I'm looking at the code thru putty, and the copy and
paste from a terminal window leave a lot to be desired)
I've never had any such problem with PuTTY.
####################################################
#!/usr/bin/perl
Unless you enjoy pain:
use strict;
use warnings;
use LWP::Simple;
In my experience LWP::Simple is only suited to run once and throw away
scripts. For anything else the small additional effort of using the
real LWP API pays off.
$site = "http://checkip.dyndns.org";
$var = get $site;
$colloc = index($var,":");
$ip = substr($var,$colloc+2,20);
$angloc = index($ip,"<");
$ip = substr($ip,0,$angloc);
Perl has very good pattern matching. Use it.
my ($ip) = get('http://checkip.dyndns.org') =~ /Current IP Address:
(.*?)</;
open CURIP,">curip" or die "File does not exist, 'curip'";
Consider putting the actual error in the error message rather than an
random guess. Use the 3-arg open() unless you actually understand the
special legacy 2-arg form and require those semantics.
open CURIP,'>','curip' or die "$!, 'curip'";
print CURIP "$ip";
See FAQ: What's wrong with always quoting "$vars"?
close CURIP;
open OLDIP,"oldip";
Use the 3-arg open() unless you actually understand the special legacy
2-arg form and require those semantics. Always check success.
$oldip = <OLDIP>;
close OLDIP
if ( $oldip == $ip ) {
If you'd enabled warnings perl would have told you what's wrong with
that line (so I won't).
# yep, yep... print "Look the same to me, too, ain't it???\n";
}
else
{ #update dns address - run script of
# wget lines and replace old IP value
system("./updns");
system("cp -f curip oldip");
Wouldn't it make more sense to do away with the curip file and just
update the oldip file dirtectly from $ip at this point?
}
###############################################
What should I use to send the update info direct to ZoneEdit?
Well, if you want to stick to the HTTP GET API at
http://dynamic.zoneedit.com/auth/dynamic.html then you should simply
use LWP.
For an example of this download the example Perl script from the
dynamic.zoneedit.com site. (Like, duh!)
Note: this example script is not written in very good Perl.
If you want to do several requests in parallel then you could fork()
or use LWP::Parallel.
.
- Follow-Ups:
- Re: Dynamic DNS management
- From: Nooze Goy
- Re: Dynamic DNS management
- References:
- Dynamic DNS management
- From: Nooze Goy
- Dynamic DNS management
- Prev by Date: what is "}{"?
- Next by Date: Re: what is "}{"?
- Previous by thread: Dynamic DNS management
- Next by thread: Re: Dynamic DNS management
- Index(es):