#!/usr/bin/env python # # pinger.py # Host/Device Ping Utility for Windows # Corey Goldberg (www.goldb.org), 2008 # # # Pinger uses your system's ping utility to send an ICMP ECHO_REQUEST # to a list of hosts or devices. This is useful for measuring network # latency and verifying hosts are alive. import re from subprocess import Popen, PIPE from threading import Thread class Pinger(object): def __init__(self, hosts): for host in hosts: pa = PingAgent(host) pa.start() class PingAgent(Thread): def __init__(self, host): Thread.__init__(self) self.host = host def run(self): p = Popen('ping -n 1 ' + self.host, stdout=PIPE) m = re.search('Average = (.*)ms', p.stdout.read()) if m: print 'Round Trip Time: %s ms -' % m.group(1), self.host else: print 'Error: Invalid Response -', self.host if __name__ == '__main__': hosts = [ 'www.pylot.org', 'www.goldb.org', 'www.google.com', 'www.yahoo.com', 'www.techcrunch.com', 'www.this_one_wont_work.com' ] Pinger(hosts)