title: print output in csv file python
body: <p>My code that is used to print the output of the pcap file IP's IN CSV FILE is working well but the issue is it is storing only 1st packet of the pcap file. I am not getting where is the actual issue is..
  can someone help me to solve this then please.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import dpkt
  from dpkt.ip import IP
  from dpkt.ethernet import Ethernet
  import struct
  import socket
  import csv
  
  def ip_to_str(address):
      return socket.inet_ntoa(address)
  
  f = open('sample.pcap', 'rb')
  pcap = dpkt.pcap.Reader(f)
  for ts, buf in pcap:
      eth = dpkt.ethernet.Ethernet(buf)
      if eth.type != dpkt.ethernet.ETH_TYPE_IP:
          continue
  
      ip = eth.data
      do_not_fragment = bool(dpkt.ip.IP_DF)
      more_fragments = bool(dpkt.ip.IP_MF)
      fragment_offset = bool(dpkt.ip.IP_OFFMASK)
      c = csv.writer(open("a.csv", "wb"))
  
      Source = "%s" % ip_to_str(ip.src)
      Destination = "%s" % ip_to_str(ip.dst)
      Length = "%d" % (ip.len)
      TTL = "%d" % (ip.ttl)
      OFF = ip.off
      TOS = ip.tos
      Protocol = ip.p
      data = (Source, Destination, Length, TTL, TOS, OFF, Protocol)
      c.writerow(data)
  </code></pre>