def packet_import_to_db(filename, dbTableName): f = open(filename, 'rb') try: pcap = dpkt.pcap.Reader(f) except: f.close() return i = 1 #报文编号,记录wireshark中的序号,便于调试 if commonlib.IsSupportMutiThread() != 0: thread.start_new_thread(httpmutithread.httpThreadDataProcess, (dbTableName, 1)) for ts, buf in pcap: if commonlib.IsSupportMutiThread() != 0: while True: if httpmutithread.GetThreadNum() < 16: thread.start_new_thread(httpmutithread.httpThreadProcess, (buf, dbTableName, ts)) break else: time.sleep(0.01) else: httpparse.httpPacketParse(buf, dbTableName, ts) i = i + 1 #多线程时,有后台任务写,执行到这里,数据还没有准备好,这里打印不准确 if commonlib.IsSupportMutiThread() == 0: if i % 3000 == 0: print '正在读取pcap文件到数据库中,请稍等' f.close() return
def packet_import_to_db(filename,dbTableName): f = open(filename,'rb') try: pcap = dpkt.pcap.Reader(f) except: f.close() return i = 1#报文编号,记录wireshark中的序号,便于调试 if commonlib.IsSupportMutiThread() != 0: thread.start_new_thread(httpmutithread.httpThreadDataProcess,(dbTableName,1) ) for ts,buf in pcap: if commonlib.IsSupportMutiThread() != 0: while True: if httpmutithread.GetThreadNum() < 16: thread.start_new_thread(httpmutithread.httpThreadProcess, (buf,dbTableName,ts)) break else: time.sleep(0.01) else: httpparse.httpPacketParse(buf,dbTableName,ts) i = i+1 #多线程时,有后台任务写,执行到这里,数据还没有准备好,这里打印不准确 if commonlib.IsSupportMutiThread() == 0: if i%3000 == 0: print '正在读取pcap文件到数据库中,请稍等' f.close() return
def httpThreadProcess(buf,dbTableName,ts): addThreadNum() httpparse.httpPacketParse(buf,dbTableName,ts) delThreadNum() thread.exit_thread()
def httpThreadProcess(buf, dbTableName, ts): addThreadNum() httpparse.httpPacketParse(buf, dbTableName, ts) delThreadNum() thread.exit_thread()