If gethostbyname fails it never recovers

Discussion in 'Perl' started by Andrew DeFaria, Oct 5, 2006.

  1. I've been having problems with my ISP. One way it seems to manifest
    itself is that I can not reach or contact my ISP's DNS servers. IOW a
    simply nslookup google.com will fail.

    So I tried writing a script that would monitor this. The script calls
    gethostbyname for google.com every 15 minutes and logs the status. When
    gethostbyname fails however it never comes back. My ISP and internet
    connection may come back and nslookup at the command line will work
    fine. But my script will report failure at the next and following 15
    minute intervals. This is very unexpected. What am I doing wrong and is
    there a way to "reset" things so that it will start working again.

    Here's a snippet:

    sub CheckDNS {
    my $host = shift;

    my @ipaddrs = gethostbyname $host;
    my $status = $?;

    if ($status ne 0 and $debug) {
    debug "Host: $host ($status)";
    } # if

    return $status
    } # CheckDNS

    CheckDNS is called every 15 minutes with "google.com" as a parm. When a
    failure happens $status = 2 and remains = 2 forever.

    --

    Andrew DeFaria <http://defaria.com>
    Dain bramaged.
     
    Andrew DeFaria, Oct 5, 2006
    #1
    1. Advertising

  2. >>>>> "Andrew" == Andrew DeFaria <> writes:

    Andrew> So I tried writing a script that would monitor this. The script calls
    Andrew> gethostbyname for google.com every 15 minutes and logs the status. When
    Andrew> gethostbyname fails however it never comes back. My ISP and internet
    Andrew> connection may come back and nslookup at the command line will work fine. But
    Andrew> my script will report failure at the next and following 15 minute
    Andrew> intervals. This is very unexpected. What am I doing wrong and is there a way
    Andrew> to "reset" things so that it will start working again.

    Andrew> Here's a snippet:

    Andrew> sub CheckDNS {
    Andrew> my $host = shift;

    Andrew> my @ipaddrs = gethostbyname $host;
    Andrew> my $status = $?;

    Andrew> if ($status ne 0 and $debug) {
    Andrew> debug "Host: $host ($status)";
    Andrew> } # if

    Andrew> return $status
    Andrew> } # CheckDNS

    Andrew> CheckDNS is called every 15 minutes with "google.com" as a parm. When a
    Andrew> failure happens $status = 2 and remains = 2 forever.

    $? is not set for a gethostbyname failure. In fact, I'm not sure
    anything is actually set.

    And now a word from our Usenet manager...

    If you can see this message, you are reading a group that is not
    officially carried, and therefore doesn't get the propogation or
    readership that the official comp.lang.perl.misc group gets.

    What this means TO YOU is that your question won't be answered
    to the same expert level that an official group will get. You'll
    get answers that are wrong (and not noticed to be wrong), or no
    answer at all.

    STOP POSTING HERE. POST TO COMP.LANG.PERL.MISC

    And send email to your news server administrator to PLEASE DELETE THIS
    GROUP.

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

    --
    Posted via a free Usenet account from http://www.teranews.com
     
    Randal L. Schwartz, Oct 5, 2006
    #2
    1. Advertising

  3. Randal L. Schwartz wrote:
    > $? is not set for a gethostbyname failure. In fact, I'm not sure
    > anything is actually set.

    Actually, at least on my system... it is! If I change $host = "bogus"
    gethostbyname sets $? to 1. Try it!
    > And now a word from our Usenet manager...
    >
    > If you can see this message, you are reading a group that is not
    > officially carried, and therefore doesn't get the propogation or
    > readership that the official comp.lang.perl.misc group gets.
    >
    > What this means TO YOU is that your question won't be answered to the
    > same expert level that an official group will get. You'll get answers
    > that are wrong (and not noticed to be wrong), or no answer at all.
    >
    > STOP POSTING HERE. POST TO COMP.LANG.PERL.MISC
    >
    > And send email to your news server administrator to PLEASE DELETE THIS
    > GROUP.

    Thanks. I had no idea. I will post there...

    --

    Andrew DeFaria <http://defaria.com>
    I got a new shadow. I had to get rid of the other one -- it wasn't doing
    what I was doing.
     
    Andrew DeFaria, Oct 6, 2006
    #3
    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. Soren Kuula
    Replies:
    1
    Views:
    491
    Henry S. Thompson
    Dec 1, 2005
  2. Kevin
    Replies:
    4
    Views:
    457
    Irrwahn Grausewitz
    Oct 17, 2003
  3. Eric Brunel
    Replies:
    0
    Views:
    1,532
    Eric Brunel
    Oct 27, 2003
  4. 'gethostbyname' fails Please Help

    , Jul 24, 2008, in forum: C Programming
    Replies:
    4
    Views:
    427
  5. Andrew DeFaria

    If gethostbyname fails it never recovers

    Andrew DeFaria, Oct 6, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    209
    Peter J. Holzer
    Oct 7, 2006
Loading...

Share This Page