Gather clients on AP.
This commit is contained in:
parent
07ca7ddcfd
commit
4028d92e61
1 changed files with 43 additions and 6 deletions
|
@ -18,16 +18,53 @@ def convert_timestamp_to_epoch(ts_string):
|
||||||
print(f"[!] Failed to parse timestamp: {ts_string}")
|
print(f"[!] Failed to parse timestamp: {ts_string}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def analyze_pcap(pcapng_path, start_ts, end_ts):
|
def get_clients_on_ap(capture, ap_bssid):
|
||||||
|
clients = set()
|
||||||
|
|
||||||
|
for packet in capture:
|
||||||
|
try:
|
||||||
|
if not hasattr(packet, 'wlan'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
sa = packet.wlan.sa
|
||||||
|
da = getattr(packet.wlan, 'da', None)
|
||||||
|
bssid = getattr(packet.wlan, 'bssid', None)
|
||||||
|
|
||||||
|
# Skip if AP is the sender
|
||||||
|
if sa == ap_bssid:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Count if the AP is the target or part of the BSSID context
|
||||||
|
if da == ap_bssid or bssid == ap_bssid:
|
||||||
|
clients.add(sa)
|
||||||
|
|
||||||
|
except AttributeError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
return len(clients)
|
||||||
|
|
||||||
|
def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel):
|
||||||
|
|
||||||
|
cap = pyshark.FileCapture(
|
||||||
|
pcapng_path,
|
||||||
|
display_filter=f'time >= {start_ts} && time <= {end_ts}',
|
||||||
|
use_json=True,
|
||||||
|
include_raw=False
|
||||||
|
)
|
||||||
|
|
||||||
|
clients_on_ap = get_clients_on_ap(cap, ap_bssid.lower())
|
||||||
|
|
||||||
# Placeholder: Logic will be added for:
|
# Placeholder: Logic will be added for:
|
||||||
# - ClientsOnAP
|
|
||||||
# - ClientsOnChannel
|
# - ClientsOnChannel
|
||||||
# - APsOnChannel
|
# - APsOnChannel
|
||||||
# - CongestionScore
|
# - CongestionScore
|
||||||
# - AvgAPSignal
|
# - AvgAPSignal
|
||||||
# - StrongestAPSignal
|
# - StrongestAPSignal
|
||||||
# - UnlinkedDevices
|
# - UnlinkedDevices
|
||||||
return 0, 0, 0, None, None, None, 0
|
|
||||||
|
cap.close()
|
||||||
|
|
||||||
|
return clients_on_ap, 0, 0, None, None, None, 0
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
@ -51,8 +88,6 @@ def main():
|
||||||
finally:
|
finally:
|
||||||
cap.close()
|
cap.close()
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
with open(args.csv, newline='') as infile, open(args.output, 'w', newline='', encoding='utf-8') as outfile:
|
with open(args.csv, newline='') as infile, open(args.output, 'w', newline='', encoding='utf-8') as outfile:
|
||||||
reader = csv.DictReader(infile)
|
reader = csv.DictReader(infile)
|
||||||
fieldnames = reader.fieldnames + [
|
fieldnames = reader.fieldnames + [
|
||||||
|
@ -65,12 +100,14 @@ def main():
|
||||||
for row in reader:
|
for row in reader:
|
||||||
tstart = convert_timestamp_to_epoch(row.get("StartTimestamp"))
|
tstart = convert_timestamp_to_epoch(row.get("StartTimestamp"))
|
||||||
tend = convert_timestamp_to_epoch(row.get("EndTimestamp"))
|
tend = convert_timestamp_to_epoch(row.get("EndTimestamp"))
|
||||||
|
ap_bssid = row.get("BSSID", "").strip().lower()
|
||||||
|
ap_channel = row.get("Channel")
|
||||||
|
|
||||||
if not tstart or not tend:
|
if not tstart or not tend:
|
||||||
writer.writerow(row)
|
writer.writerow(row)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
clients_ap, clients_chan, aps_chan, congestion, avg_signal, strongest_signal, unlinked = analyze_pcap(args.pcapng, tstart, tend)
|
clients_ap, clients_chan, aps_chan, congestion, avg_signal, strongest_signal, unlinked = analyze_pcap(args.pcapng, tstart, tend, ap_bssid, ap_channel)
|
||||||
|
|
||||||
row.update({
|
row.update({
|
||||||
'ClientsOnAP': clients_ap,
|
'ClientsOnAP': clients_ap,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue