0

I'm trying to put a counter on pair of every mac and ip received . while debugging the counter showing how many times i got an entry but printing it showing 0 everytime

import pyshark
from collections import Counter


# Creating a file capture, give path of your captured file, adding display filter
capture = pyshark.LiveCapture(interface='Wi-Fi', display_filter='arp or udp.port eq 67')
capture.sniff_continuously()
d = dict()
count1 = Counter()                                      
empty_mac = ('00:00:00:00:00:00', 'ff:ff:ff:ff:ff:ff')

# Running for loop for extracting fields from captured packets
for packet in capture:
    try:
        d["Arp_IP"] = packet.arp.dst_proto_ipv4 
        d["Arp_Mac"] = packet.arp.dst_hw_mac
        #milli_time = packet.sniff_timestamp

    except AttributeError:
        pass

    count1.update([(d['Arp_IP'], d['Arp_Mac'])])
    if d["Arp_Mac"] not in empty_mac:
        print(packet.sniff_timestamp, count1[(d['Arp_Mac'], d['Arp_IP'])], d['Arp_Mac'], d['Arp_IP'])

current OP:

1672138792.786440000 0 14:13:3x:42:xx:xx 192.168.1.5
1672138793.365195000 0 14:13:3x:42:xx:xx 192.168.1.10
1672138792.786440000 0 14:13:3x:42:xx:xx 192.168.1.5
1672138793.365195000 0 14:13:3x:42:xx:xx 192.168.1.10

Expected OP:

1672138792.786440000 1 14:13:3x:42:xx:xx 192.168.1.5
1672138793.365195000 1 14:13:3x:42:xx:xx 192.168.1.10
1672138792.786440000 2 14:13:3x:42:xx:xx 192.168.1.5
1672138793.365195000 2 14:13:3x:42:xx:xx 192.168.1.10
roXx
  • 69
  • 9

0 Answers0