title: How to count how many times an IP packet with the same IP appears in pcap file then display items from the highest amount to the lowest in python
body: <pre><code>import socket
  import dpkt
  
  
  def print_pcap(pcap):
      &quot;&quot;&quot;print source and destination IP addresses for all packets
      &quot;&quot;&quot;
      for (unused_ts, buf) in pcap:
          eth = dpkt.ethernet.Ethernet(buf)
          ip = eth.data
          src = socket.inet_ntoa(ip.src)
          dst = socket.inet_ntoa(ip.dst)
         
          
  
  def main():
      &quot;&quot;&quot;test case&quot;&quot;&quot;
      pcap_file = &quot;evidence-packet-analysis.pcap&quot;
      with open(pcap_file, &quot;rb&quot;) as file:
          pcap = dpkt.pcap.Reader(file)
          print(f&quot;[*] analysing {pcap_file} for packets&quot;)
          print_pcap(pcap)
  
  
  if __name__ == &quot;__main__&quot;:
      main()
  </code></pre>