TypeError:'pcapObject'对象不可迭代
#!/usr/bin/env python2
from multiprocessing import Process
import pcap
import sys
import string
from multiprocessing import Pool
def capture_f(p):
# print "Size Of Queue: %d" %n
return p.next()
def parsing_f(buffer):
print len(buffer)
p = pcap.pcapObject()
packet_buffer = []
pool = Pool(4)
if len(sys.argv) < 3:
print 'usage: sniff.py <interface> <expr>'
sys.exit(0)
dev = sys.argv[1]
p.open_live(dev, 1600, 0, 100)
p.setfilter(string.join(sys.argv[2:], ' '), 0, 0)
try:
while 1:
packet_buffer = pool.map(capture_f, p)
temp_buffer = packet_buffer
del packet_buffer[:]
radius_reader = Process(target=parsing_f, args=(temp_buffer,))
radius_reader.daemon = True
radius_reader.start()
except KeyboardInterrupt:
print '%s' % sys.exc_type
print 'shutting down'
print '%d packets received, %d packets dropped, %d packets dropped by interface' % p.stats()
但我得到例外:
Traceback(最近一次调用的最后一个):第29行,在packet_buffer = pool.map(capture_f,p)中的文件“script.py”,第251行的文件“/usr/lib/python2.7/multiprocessing/pool.py”在map中返回self.map_async(func,iterable,chunksize).get()文件“/usr/lib/python2.7/multiprocessing/pool.py”,第304行,在map_async中iterable = list(iterable)TypeError:'pcapObject '对象不可迭代
我想要的只是捕获多处理池中的数据包。 任何帮助,将不胜感激。 提前Thanx。
链接地址: http://www.djcxy.com/p/9421.html