update script
This commit is contained in:
parent
c7f8005c0f
commit
6b62de7d35
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
_*/
|
_*/
|
||||||
*bin
|
*bin
|
||||||
|
*pcap
|
@ -11,7 +11,7 @@ def signal_handler(sig, frame):
|
|||||||
global stop_event
|
global stop_event
|
||||||
stop_event.set()
|
stop_event.set()
|
||||||
|
|
||||||
def capture_traffic(interface, ip, port):
|
def capture_traffic(interface, ip='192.168.0.56', port=5000):
|
||||||
global stop_event
|
global stop_event
|
||||||
|
|
||||||
stop_event = Event()
|
stop_event = Event()
|
||||||
@ -20,7 +20,7 @@ def capture_traffic(interface, ip, port):
|
|||||||
|
|
||||||
def create_filename(interface):
|
def create_filename(interface):
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
return f"{now.strftime('%Y%m%d_%H%M')}_{interface}_{int(time.time())}.pcap"
|
return f"captures/{now.strftime('%Y%m%d_%H%M')}_{interface}_{int(time.time())}.pcap"
|
||||||
|
|
||||||
def save_packets(packets, filename):
|
def save_packets(packets, filename):
|
||||||
wrpcap(filename, packets)
|
wrpcap(filename, packets)
|
||||||
@ -40,16 +40,24 @@ def capture_traffic(interface, ip, port):
|
|||||||
print(f"Sent {filename} to {ip}:{port}")
|
print(f"Sent {filename} to {ip}:{port}")
|
||||||
|
|
||||||
while not stop_event.is_set():
|
while not stop_event.is_set():
|
||||||
|
start_time = time.time()
|
||||||
filename = create_filename(interface)
|
filename = create_filename(interface)
|
||||||
packets = sniff(iface=interface, timeout=5*60, stop_filter=lambda x: stop_event.is_set())
|
packets = sniff(iface=interface, timeout=30*1, stop_filter=lambda x: stop_event.is_set())
|
||||||
save_packets(packets, filename)
|
save_packets(packets, filename)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) != 4:
|
if len(sys.argv) < 2 or len(sys.argv) > 4:
|
||||||
print(f"Usage: {sys.argv[0]} <interface> <ip> <port>")
|
print(f"Usage: {sys.argv[0]} <interface> [ip] [port]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
interface = sys.argv[1]
|
interface = sys.argv[1]
|
||||||
ip = sys.argv[2]
|
ip = sys.argv[2] if len(sys.argv) > 2 else '192.168.0.56'
|
||||||
port = int(sys.argv[3])
|
port = int(sys.argv[3]) if len(sys.argv) > 3 else 5000
|
||||||
|
|
||||||
|
start_time = datetime.now()
|
||||||
|
print(f"Script started at: {start_time.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||||
|
|
||||||
capture_traffic(interface, ip, port)
|
capture_traffic(interface, ip, port)
|
||||||
|
|
||||||
|
end_time = datetime.now()
|
||||||
|
print(f"Script ended at: {end_time.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||||
|
Reference in New Issue
Block a user