0
votes

I have program for extract PCAP ARP src_ip and Dest_IP and save in CSV file. i need code how to count Number of Times Src_IP is request to dest_ip (Example 192.168.0.1 src_IP try to connected 10 times with Dest_ip). so how to count duplicates IP in a Column. or how to count src to dest IP or any other idea for count duplicate IP in a Column pls.

below code I need to count number of times src to target

    for ts, buf in pcap:

        eth = dpkt.ethernet.Ethernet(buf)

        # If the packet is not arp

        if eth.type != 2054:
            continue
        try:
            arp = eth.arp
        except Exception as e:
            continue

        packet_time = datetime.datetime.utcfromtimestamp(ts).strftime("%m/%d/%Y,%H:%M:%S")

        src = dpkt.socket.inet_ntoa(arp.spa)
        tgt = dpkt.socket.inet_ntoa(arp.tpa)
1
Hi Eric, Thanks for your reply. here counter can count from list. but i need count from csv column. so it will work? - delwar.naist
You can use the csv module to read a CSV file! Python has quite a bit of useful functionality built into its standard library. docs.python.org/3/library/csv.html - Eric Fulmer
Thanks Eric for your suggestion... - delwar.naist

1 Answers

1
votes

Use csv to load desired IPs into a list and then do something like:

from collections import Counter
Counter(ip_list)