-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuse_tcpdump.py
26 lines (22 loc) · 1.14 KB
/
use_tcpdump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from scapy.all import sniff, wrpcap
import datetime
from utils import save_results
def use_tcpdump(interface, filter_expression, packet_count):
captured_packets = []
def packet_handler(packet):
print(packet.show())
captured_packets.append(packet)
try:
print(f"Iniciando a captura de pacotes na interface {interface}. Pressione CTRL+C para interromper.")
sniff(iface=interface, filter=filter_expression, prn=packet_handler, count=packet_count, store=0)
except Exception as e:
print(f"Erro ao capturar pacotes: {e}")
finally:
save = input("Deseja salvar os resultados? (s/n): ")
if save.lower() == 's':
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"captura_{interface}_{timestamp}.pcap"
wrpcap(filename, captured_packets)
save_results(filename, "captura_tcpdump", f"capturas_tcpdump_{timestamp}.pcap")
print(f"Captura de pacotes finalizada. Pacotes salvos em: captura_tcpdump/capturas_tcpdump_{timestamp}.pcap")
print(">>> Use a opção 8 para ler os arquivos .pcap gerados <<<")