from time import sleep from scapy.all import ICMP, IP, Dot1Q, Ether, sendp, AsyncSniffer, wrpcap from tqdm import tqdm a = AsyncSniffer(iface="enp5s0d1", filter="icmp") b = AsyncSniffer(iface="enp2s0", filter="icmp") a.start() b.start() for i in tqdm(range(0, 4095)): sendp( Ether(dst="00:02:c9:27:10:73", src="00:f0:cb:ef:e0:3b") / Dot1Q(vlan=i) / IP(dst="10.0.45.45", src="10.0.45.5") / ICMP(id=i), iface="enp2s0", verbose=False, ) print("Wrapping up and waiting for last packets") sleep(1) plist = a.stop() plist_ingress = b.stop() seen = [False for i in range(4095)] icmpid = [False for i in range(4095)] def pprint(seen): last = None s = "" for k, v in enumerate(seen): if v and last is None: last = k s += str(k) if not v and last is not None: if k-1 == last: s += "," else: s += f"-{k-1}," last = None if last is not None and last < k: s += f"-{k}" return s + "\n" for p in plist: if Dot1Q in p: vlan = int(p[Dot1Q].vlan) seen[vlan] = True if ICMP in p and p[ICMP].id == vlan: icmpid[vlan] = True print("Icmp correspondance") print(pprint(icmpid)) print("Seen vlans") print(pprint(seen)) print("Collecting :") import subprocess from datetime import datetime from pathlib import Path import shutil import sys timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + "-test_all_vlans" log_dir = Path("./logs") / timestamp log_dir.mkdir(parents=True, exist_ok=True) with open(log_dir / "seen_vlans.txt", "w") as f: f.write(pprint(seen)) with open(log_dir / "seen_icmp_ids.txt", "w") as f: f.write(pprint(icmpid)) shutil.copy(Path(sys.argv[0]), log_dir / sys.argv[0]) print(" - [x] script.py") with open(log_dir / "egress.pcap", "wb") as file: wrpcap(file, plist) with open(log_dir / "ingress.pcap", "wb") as file: wrpcap(file, plist_ingress) print(" - [x] pcap") cmd_config = ["ssh", "-o", "StrictHostKeyChecking=no", "root@192.168.42.6", "cli show config"] cmd_rsi = ["ssh", "-o", "StrictHostKeyChecking=no", "root@192.168.42.6", "cli request support information"] result = subprocess.run(cmd_config, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) with open(log_dir / "config.txt", "w") as f: f.write(result.stdout) print(" - [x] config") print("Finished, saved to", log_dir)