Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if remote host is up in Python

How would I check if the remote host is up without having a port number? Is there any other way I could check other then using regular ping.

There is a possibility that the remote host might drop ping packets

like image 353
user140736 Avatar asked Mar 28 '10 23:03

user140736


2 Answers

This worked fine for me:

HOST_UP  = True if os.system("ping -c 1 " + SOMEHOST) is 0 else False
like image 133
jmunsch Avatar answered Sep 25 '22 02:09

jmunsch


A protocol-level PING is best, i.e., connecting to the server and interacting with it in a way that doesn't do real work. That's because it is the only real way to be sure that the service is up. An ICMP ECHO (a.k.a. ping) would only tell you that the other end's network interface is up, and even then might be blocked; FWIW, I have seen machines where all user processes were bricked but which could still be pinged. In these days of application servers, even getting a network connection might not be enough; what if the hosted app is down or otherwise non-functional? As I said, talking sweet-nothings to the actual service that you are interested in is the best, surest approach.

like image 24
Donal Fellows Avatar answered Sep 26 '22 02:09

Donal Fellows