Dynamic DNS management

Discussion in 'Perl Misc' started by Nooze Goy, May 2, 2007.

  1. Nooze Goy

    Nooze Goy Guest

    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?
    Nooze Goy, May 2, 2007
    #1
    1. Advertising

  2. On May 2, 12:42 am, Nooze Goy <> 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, 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.
    Brian McCauley, May 2, 2007
    #2
    1. Advertising

  3. Nooze Goy

    Nooze Goy Guest

    Brian McCauley wrote:
    > On May 2, 12:42 am, Nooze Goy <> 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, 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.


    How?
    Nooze Goy, May 3, 2007
    #3
  4. On May 3, 5:51 pm, Nooze Goy <> wrote:
    > Brian McCauley wrote:
    > > On May 2, 12:42 am, Nooze Goy <> wrote:


    [ talking about a Unix shell script ]

    > >> 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


    > >> 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.

    >
    > How?


    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:

    &
    Brian McCauley, May 3, 2007
    #4
  5. Nooze Goy

    Nooze Goy Guest

    Brian McCauley wrote:
    > On May 3, 5:51 pm, Nooze Goy <> wrote:
    >> Brian McCauley wrote:
    >>> On May 2, 12:42 am, Nooze Goy <> wrote:

    >
    > [ talking about a Unix shell script ]
    >
    >>>> 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

    >
    >>>> 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.

    >> How?

    >
    > 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.
    Nooze Goy, May 3, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Floris van Haaster

    Project management / bug management

    Floris van Haaster, Sep 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,229
    Jon Paal
    Sep 23, 2005
  2. pouet
    Replies:
    2
    Views:
    737
    Will Hartung
    Jul 30, 2004
  3. Torsten Schmeissel

    dynamic subdomain without DNS

    Torsten Schmeissel, Mar 31, 2005, in forum: Java
    Replies:
    2
    Views:
    7,377
    Torsten Schmeissel
    Apr 5, 2005
  4. Sam Roberts
    Replies:
    0
    Views:
    194
    Sam Roberts
    Mar 20, 2005
  5. gavino
    Replies:
    2
    Views:
    153
    Ted Zlatanov
    Jul 27, 2006
Loading...

Share This Page