-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (35 loc) · 1.36 KB
/
Copy pathmain.py
File metadata and controls
51 lines (35 loc) · 1.36 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import signal
import sys
import atexit
from detect import detect_wifi_interface, detect_hotspot_interface, ip_of
from firewall import setup_captive_portal, reset_firewall, start_hotspot, stop_hotspot
from server import start_server, set_hotspot_iface
from sessions import delete_sessions
def cleanup():
print("[+] Limpiando firewall…")
reset_firewall()
delete_sessions()
print("[+] Apagando hotspot…")
stop_hotspot()
sys.exit(0)
def signal_handler(sig, frame):
cleanup()
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
atexit.register(cleanup)
def main():
# ARRANCA hostapd, dnsmasq y crea wlan1
start_hotspot()
# Detectar interfaz del hotspot (AP) y su IP (típicamente 10.x.x.x o 192.168.x.x)
hotspot_iface = detect_hotspot_interface()
hotspot_ip = ip_of(hotspot_iface)
# Detectar interfaz con salida a internet (WAN) para NAT
wan_iface = detect_wifi_interface()
# Guardar la interfaz hotspot en el servidor para usarla al autorizar IPs
set_hotspot_iface(hotspot_iface)
# Configurar reglas de portal cautivo (redirigir HTTP y activar NAT)
setup_captive_portal(hotspot_iface, hotspot_ip, portal_port=8080, wan_iface=wan_iface)
# Iniciar servidor enlazado a la IP del hotspot
start_server(hotspot_ip, port=8080)
if __name__ == "__main__":
main()