Ping host script

Hi, I am confused on how to get the module working.

Could someone write me a simple script that will ping a host, let's say and return the result to the command line using the module?  

I am using windows xp and have installed the module I downloaded from

Who is Participating?
drush_kodersConnect With a Mentor Commented:
If you're having problems integrating other modules, then another way to approach the problem is to use the existing "os" module to call the native Windows ping function. Here's a simple one-liner that spits out the output of a native call to ping. It should work out of the box.

import os
print os.popen('ping -n 1').read()

I found another example of the same approach at koders:

The "-n 1" argument to ping is to tell it to only send one ping packet.
There is a more comprehensive ping module that is part of the QOS project - which incidentally can monitor a lot more than just responsiveness to IP traffic. (If you need it)

In any event, here is a snippet that times a ping:
        pingTime = time.time()
        # ping first
        result = 0
        for i in range(3):
                result =['pingHost'], 2)
            if (result == 1):

        pingTime = time.time() - pingTime
        pingCount = i
        se['WpingTime'] = '%0.3f' % pingTime
        se['WpingCount'] = '%0d' % pingCount
        if (result != 1):
            se['Wstatus'] = 'P'
            se['Wmesg']   = "Can't ping"

You can see the rest of the code here:

AirgazmAuthor Commented:
I'm just experimenting with Python, (very new to it) and wanted to write a very simple program that pings a few hosts, so I thought I would start small.

I am trying to make heads or tails of the above code.  Should there be some import statements, for ping and system, etc in there?  I can't get it to work correctly.  I get an error "se not defined".

Couldn't we trim the script down to a very simple ping just one host

I was figuring it was as simple as something like

import sys, ping
responce = ping('')
print responce

Thanks, and sorry for being a newb. :)
AirgazmAuthor Commented:
Ahh, thanks, thats a good start.  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.