Dynamic DNS management

N

Nooze Goy

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, butt
hu nose?

Obviously, with five or six domains, you're going to be hard-pressed to
update the IP every minute, 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, and maybe a) that'll be faster or b)
there's some way to update all the domains in the list either with one
string or in a loop.

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)

####################################################
#!/usr/bin/perl
use LWP::Simple;

$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);
open CURIP,">curip" or die "File does not exist, 'curip'";
print CURIP "$ip";
close CURIP;
open OLDIP,"oldip";
$oldip = <OLDIP>;
close OLDIP
if ( $oldip == $ip ) {
# 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");
}
###############################################


What should I use to send the update info direct to ZoneEdit?
 
B

Brian McCauley

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, butt
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.
 
B

Brian McCauley

[ talking about a Unix shell script ]

You are asking (in a Perl newsgroup) how, in a Unix shell script, to
indicate that the script should not wait for one command to complete
before going on to the next!

What's wrong with this picture?

Oh, well, I guess seeing as it's a single character answer:

&
 
N

Nooze Goy

Brian said:
[ talking about a Unix shell script ]

You are asking (in a Perl newsgroup) how, in a Unix shell script, to
indicate that the script should not wait for one command to complete
before going on to the next!

What's wrong with this picture?

There's nothing wrong with the picture - there's a flaw in your
attitude. No question was asked about the script, but you chose to make
a statement about it. Now you act amazed that there was a response to
that...

Man, if you don't want to help, then don't answer. If you're going to
change directions, then don't jump sh!tty when your direction is followed.

Basically, what's wrong is that YOU offered a response to a question
that wasn't asked. You could have taken the few seconds to explain, but
apparently you were too busy deconstructing my crappy little Perl script
- which, as pathetic as it may be, does in fact work. Near as I could
tell, the slowth is on the other end, at least through its current
access method, but I thought perhaps someone else might be handling
dyndns differently and have something useful to offer.

My mistake. Thanks, anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top