#!/bin/env python#-*-coding:utf-8-*-# @Date: 2015-09-06 11:30:48# @Author: Your Name ([email protected]) # @ link:http://example.org# @Version: $Id $import threadingimport commandsimport timedef py_mtr (IP): Isotimeforma t= '%y-%m-%d%x ' Time_now=time.strftime (Isotimeformat,time.localtime ()) filename= '/tmp/' +ip+ '. txt ' f= Open (filename, ' W ') F.write (time_now) f.write (' \ n ') mtr_out=commands.getstatusoutput ("Mtr-r-C 20-n %s "%ip) [1] Time_now=time.strftime (Isotimeformat,time.localtime ()) F.write (mtr_out) f.write (' \ n ') F.write (Time_now) f.write (' \ n ') f.close () if __name__== ' __main__ ': ip_target=[' 1.1.1.1 ', ' 2.2.2.2 ', ' 3.3.3.3 '] threads = [] #多线程 print "Begin ..." for I in ip_target:a=threading. Thread (target=py_mtr,args= (i,)) A.start () Threads.append (a) # waits for all threads to complete # For T in Threads: # T.join () print "Exiting Main Thread"
Multithreaded mtr-Code