1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #!/bin/env python # -*- coding: utf-8 -*- # @Date : 2015-09-06 11:30:48 # @Author : Your Name (you@example.org) # @Link : http://example.org # @Version : $Id$ import threading import commands import time def Py_Mtr(ip): ISOTIMEFORMAT = '%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) # 等待所有线程完成 # for t in threads: # t.join() print "Exiting Main Thread" |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步