multiping + while loop + excel

Fransiska M Argasetya acquiesce11 at
Sun Sep 17 15:56:08 CEST 2006

dear everyone
  please help me with my coding dilemma o_O
  i have a python code that can ping several sites as shown below:
  import threading
import os
import Queue
import time
from time import sleep
  def showResponse(args):
    """Pretty prints passed tuple to stdout"""
      ip, stdoutLi, threadName = args
    print '%s \t\t\t\t\t\n' % (ip)
      for line in stdoutLi:
        line = line.strip()
        if not line: continue
        print '\t' + line
    print '-'*72
  class Pinger(threading.Thread):
      def __init__(self, host, queue):
        self.__host = host
        self.__queue = queue
      def run(self):
        pingCmd = "ping -n 1 -w 1000 " + self.__host
        childStdout = os.popen(pingCmd)
        result = (self.__host, childStdout.readlines(), self.getName())
if __name__ == '__main__':
    hostLi = ['','',''] # read from the list
      q = Queue.Queue()
      startA = time.time()
    for host in hostLi:
        """Create and start all necessary threads, passing results
        back via thread safe Queue instance.
      i = len(hostLi) # counts the length of hostLi
    while i > 0:
        i -= 1

  i would like to develop it more with the following requirements:
  1). i want to make the code to read the list of websites from another file (be it a .txt or .xls)
  2). i want the results of the pings to be displayed in another file, where i can manipulate those figures later on for research purposes
  3). if number (2) is achieved, i want the code to run every 60 minutes so i can make a statistic with those values, i.e. pinging to site A has less delay during the day compare to during night time or something like that
  i have several ideas of my own but they dont seem to work:
  1). hostLi = open("ipaddress.txt")  # ipaddress.txt is the list of websites
     for line in hostLi.readlines():
          print line
       f = open("ipaddress.txt")
     while 1:
          line = f.readline()
          if not line: break
  2). myoutfile = showResponse(q.get()) # write this result to the file
     theoutfile = open ("myout.txt","w") # open the file to write (w)
     for item in myoutfile:  # write out the contents
          theoutfile.write (item)
  3). while i > 0:
        i -= 1
    while 1:
        time.sleep(3600)  # 60 minutes = 3600 seconds
  thank you very much for anyone who can help me out with these issues
  really appreciate it a lot!

On Yahoo!7 
  Answers: 25 million answers and counting. Learn something new today
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list