i want to update only counter fields if a new packet arrives. other fields will remain exist with no dupes and just update counter field
import pyshark
from collections import Counter
capture = pyshark.LiveCapture(interface='wlo2', bpf_filter='arp')
capture.sniff(timeout=5)
keys = {}
e_mac = '00:00:00:00:00:00'
already_seen = []
count = Counter()
for packet in capture:
keys['ip'] = packet.arp.dst_proto_ipv4
keys['mac'] = packet.arp.dst_hw_mac
seen = keys['mac'], keys['ip']
count.update([(keys['mac'], keys['ip'])])
if keys['mac'] not in e_mac:
if seen not in already_seen:
already_seen.append(seen)
print(packet.sniff_time, count[(keys['mac'], keys['ip'])], keys['mac'], keys['ip'])
The output i receiving:
2021-12-07 11:20:59.488378 1 f8:c4:f3:56:a3:70 192.168.1.1
2021-12-07 11:21:51.942304 1 44:af:28:2c:6d:6b 192.168.1.195
2021-12-07 11:22:31.135620 1 28:d1:27:1a:12:c0 192.168.1.3
there is no update in counter as i stopping duplicate mac. if remove duplicate condition then it will start counting of every specific packet. Here i just want that counter field work dynamically and whenever i received a packet it update only counter field.