#!/usr/bin/python
import os
import fnmatch
import subprocess
import time
total = 0
for fileName in os.listdir('/pcaps/APR'):
if fnmatch.fnmatch(fileName, '*.pcap'):
print fileName
subprocess.Popen('NetReplay ......', shell=True, stdout=subprocess.PIPE)
time.sleep(5)
total = total + 1
print 'total: ', total
代码说明:
遍历指定路径文件
$ 报文存放于 /pcaps/APR 路径下,通过os模块遍历该路径
for fileName in os.listdir('/pcaps/APR')
$ 对于该路径下的文件,只发送后缀为 .pcap 的数据包,因此使用了fnmatch匹配后缀为.pcap的文件