如何用Python计算CSV中一列中的重复IP

2024-05-14 15:46:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有程序提取PCAP ARP src\u ip和Dest\u ip并保存在CSV文件中。我需要代码如何计算Src\u IP请求dest\u IP的次数(例如192.168.0.1 Src\u IP尝试与dest\u IP连接10次)。那么如何计算列中的重复IP。或如何计算src到dest IP或任何其他想法计数重复IP在一列请

下面的代码我需要计算的次数src的目标

    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)

Tags: 代码ipsrcdatetimepacket次数desteth

热门问题