I am attempting to call two_byte_proc(payload,offset) from within process() but it does not write to the output file out_buf. The output from offset or payload may contain None so those iterations should be skipped and restart the process function with the next packet.
def process():
pkts = sniff(offline="infile.pcap",filter="tcp")
out_buf = open("outfile.bin","wb")
for pkt in pkts:
offset = hexdump(str(pkt.payload)[:2])
payload = hexdump(pkt.payload)
if offset or payload is None:
pass
else:
out_buf.write(two_byte_proc(payload,offset))
process()
The expression
offset or payload is Noneis always True; perhaps you meant:instead.
Since you ‘pass’ if that expression is True, you may as well reverse it:
I suspect that
offsetandpayloadare either strings with length > 0 or None, in which case that can be further simplified to:Last but not least, you need to make sure that
two_byte_proc(orfour_byte_procafter your edit) actually returns something to write to out_buf. If all it returns is an empty string, for example, you won’t see any results.