-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor_mode.py
executable file
·34 lines (26 loc) · 1.38 KB
/
monitor_mode.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
27
28
29
30
31
32
33
34
import subprocess
def stop_network_services():
try:
subprocess.run(['sudo', 'systemctl', 'stop', 'NetworkManager'], check=True)
subprocess.run(['sudo', 'killall', 'wpa_supplicant'], check=True)
print(f"NetworkManager y wpa_supplicant stopped.")
subprocess.run(['sudo', 'airmon-ng', 'check', 'kill'], check=True)
print("Interfering processes (such as dhclient) stopped.")
except subprocess.CalledProcessError as e:
raise Exception(f"Error when stopping processes: {e}")
def enable_monitor_mode(interface):
try:
stop_network_services()
print(f"Enabling monitor mode in {interface}...")
subprocess.run(['sudo', 'airmon-ng', 'start', interface], check=True)
print(f"{interface} is now in monitor mode (wlan0mon)")
except subprocess.CalledProcessError as e:
raise Exception(f"Error when enabling monitor mode: {e}")
def disable_monitor_mode(interface):
try:
print(f"Restoring {interface} to managed mode...")
subprocess.run(['sudo', 'airmon-ng', 'stop', f'{interface}mon'], check=True)
subprocess.run(['sudo', 'systemctl', 'start', 'NetworkManager'], check=True)
print(f"{interface} is now in managed mode and NetworkManager is restarted.")
except subprocess.CalledProcessError as e:
raise Exception(f"Error when disabling monitor mode: {e}")