socket.gethostbyaddr() question

Discussion in 'Python' started by Harlin Seritt, Jan 15, 2006.

  1. I have a list of IP addresses I am testing with socket.gethostbyaddr().
    For the most part, I am able to get a hostname returned to me when I
    run gethostbyaddr(). I am also hoping this will allow me to tell if a
    computer is up or down. However, in my environment, I am finding that I
    am able to get a hostname even though I am unable to actually ping that
    server (when I ping a server i like this, I get 'request timed out'
    messages telling me that the server is not up).

    Other times, I am able to ping a server with success but the
    gethostbyaddr() request will not be able to return a hostname for me
    making me think that machine is truly down when I know it's not. Can
    anyone give me any pointers as to why this happens? Is there anyway I
    can do a reliable ping to another server with Python? I am not
    interested in doing system calls with a system Ping client (I have to
    ping way too many machines and this either takes too long or causes
    severe memory leakage due to MS's horrible ping client). Also, I am
    unable to use Jeremy Hylton's Python ping client because it does little
    more than call gethostbyaddr(). Thanks for taking a look at this.

    Harlin Seritt
     
    Harlin Seritt, Jan 15, 2006
    #1
    1. Advertising

  2. Harlin Seritt

    Roy Smith Guest

    "Harlin Seritt" <> wrote:
    > I have a list of IP addresses I am testing with socket.gethostbyaddr().
    > For the most part, I am able to get a hostname returned to me when I
    > run gethostbyaddr(). I am also hoping this will allow me to tell if a
    > computer is up or down.


    Gethostbyaddr() simply does a lookup in some sort of name resolution
    database (typically DNS, but could be YP/NIS, hostfile, etc). The ability
    to look a name up in the database has absolutely no correlation with
    whether that node is up, down, or unreachable.

    To tell if a machine is up or down, you need to probe the machine directly.
    Typically, this is done by sending it an ICMP Echo Request (commonly known
    as ping), but that's not foolproof. A machine could be up, but unreachable
    because of network or routing problems. A machine could be intentionally
    not answering pings. A firewall in the way could be filtering out ping
    packets. Or, the Echo Request or Echo Reply could have simply gotten lost
    somewhere on the network.

    What, exactly, are you trying to do?
     
    Roy Smith, Jan 15, 2006
    #2
    1. Advertising

  3. Harlin Seritt

    Steve Holden Guest

    Harlin Seritt wrote:
    > I have a list of IP addresses I am testing with socket.gethostbyaddr().
    > For the most part, I am able to get a hostname returned to me when I
    > run gethostbyaddr(). I am also hoping this will allow me to tell if a
    > computer is up or down. However, in my environment, I am finding that I
    > am able to get a hostname even though I am unable to actually ping that
    > server (when I ping a server i like this, I get 'request timed out'
    > messages telling me that the server is not up).
    >
    > Other times, I am able to ping a server with success but the
    > gethostbyaddr() request will not be able to return a hostname for me
    > making me think that machine is truly down when I know it's not. Can
    > anyone give me any pointers as to why this happens? Is there anyway I
    > can do a reliable ping to another server with Python? I am not
    > interested in doing system calls with a system Ping client (I have to
    > ping way too many machines and this either takes too long or causes
    > severe memory leakage due to MS's horrible ping client). Also, I am
    > unable to use Jeremy Hylton's Python ping client because it does little
    > more than call gethostbyaddr(). Thanks for taking a look at this.
    >

    If you have the ability to run code on the machines you are interested
    in you might want to consider Nicola Larosa's heartbeat recipe:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52302

    You may also find something useful in

    http://pynms.sourceforge.net/ping.html

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC www.holdenweb.com
    PyCon TX 2006 www.python.org/pycon/
     
    Steve Holden, Jan 15, 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. Neil Aggarwal

    gethostbyaddr returning null for CNAME records

    Neil Aggarwal, Feb 25, 2004, in forum: C Programming
    Replies:
    2
    Views:
    3,847
    Ben Pfaff
    Feb 25, 2004
  2. Mohammed Smadi

    socket.gethostbyaddr problem

    Mohammed Smadi, Sep 18, 2005, in forum: Python
    Replies:
    1
    Views:
    607
    Irmen de Jong
    Sep 18, 2005
  3. gethostbyaddr/nslookup failed

    , Jul 27, 2005, in forum: C Programming
    Replies:
    1
    Views:
    558
    Artie Gold
    Jul 27, 2005
  4. shailesh
    Replies:
    1
    Views:
    461
    Sion Arrowsmith
    Jan 28, 2008
  5. cjblaine
    Replies:
    1
    Views:
    351
    Ned Deily
    Apr 28, 2011
Loading...

Share This Page