Re: How to test whether a host is reachable?
- From: Larry Bates <lbates@xxxxxxxxxxx>
- Date: Thu, 22 Feb 2007 08:47:44 -0600
Fabian Steiner wrote:
Hello!
As the subject says I need to test whether a host computer in our
network is reachable or not. At the moment I simply attempt to connect
to a given port that is open when the machine is online:
[...]
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(('192.168.0.100', 80))
except socket.error:
print >>sys.stderr "Server offline"
sock.close()
[...]
Now I am wondering if there isn't any better method which would be more
general. In fact, I think of something like a python version of ping
which only tries to send ICMP packets. However, I don't know what the
code has to look like then. Any ideas or suggestions?
Thanks,
Fabian
Just because you could ping with ICMP packets doesn't mean you could
do anything with the machine. I assume that you are connecting to
do something on the machine. Just wrap what you are trying to do
in try: block. It will either succeed or fail. Handle the exeption.
-Larry
.
- Follow-Ups:
- Re: How to test whether a host is reachable?
- From: Diez B. Roggisch
- Re: How to test whether a host is reachable?
- References:
- How to test whether a host is reachable?
- From: Fabian Steiner
- How to test whether a host is reachable?
- Prev by Date: Re: Reading mails from Outlook
- Next by Date: Re: plugin development best practices
- Previous by thread: Re: How to test whether a host is reachable?
- Next by thread: Re: How to test whether a host is reachable?
- Index(es):
Relevant Pages
|