[BangPypers] Background ping - check for server availability

Nikunj.Badjatya at emc.com Nikunj.Badjatya at emc.com
Thu Dec 29 12:57:19 CET 2011

Oops.. take
esxname = ip

From: Badjatya, Nikunj
Sent: Thursday, December 29, 2011 5:24 PM
To: Bangalore Python Users Group - India
Subject: Background ping - check for server availability

I want to check the availability of the server ( in the sense ) by continuously pinging it in intervals of 30 seconds.
I am using Python2.7 on windows platform.
I wrote the following snippet. It works fine but it opens a windows cmd prompt everytime it is reaching subprocess.call()

import subprocess
import time

def checkserveravail(ip):
    while True:
        pingret = subprocess.call('ping {0} -n 1'.format(esxname))
        if pingret == 0:
            print("The  server {0} is not reacheable. Please check network connectivity".format(ip))



This snippet will be a part of larger program. Where a thread will be doing this job of checking server recheability.

I do not want that cmd prompt windows to open everytime and just want this job to happen in background.
I also do not want to import any external module like ping, which will unnecessarily increase the dependencies in my programs.

Any clues?


7  Switch off as you go  | qRecycle always  | P  Save Paper - Save Trees | Go Green

More information about the BangPypers mailing list