Parse pcap file into txt file
<p>How do i parse a pcap file and convert it into a text file wherein each line in the text file is a packet?</p>

<p>i tried writing it into text file as given below but special characters are showing up when i print eth. Therefore, when i try to write it into a text file, the following error shows up.</p>

<p>TypeError: expected a character buffer object</p>

<pre><code>import dpkt

f1 = open('temp.pcap')
pcap = dpkt.pcap.Reader(f1)
f2 = open('tempMan.txt', 'w')

for ts, buf in pcap:
    eth = dpkt.ethernet.Ethernet(buf)
    print eth
    f2.write(eth)
</code></pre>