|
| 1 | +import http.server |
| 2 | +import socketserver |
| 3 | +import socket |
| 4 | +from datetime import datetime |
| 5 | +import requests |
| 6 | + |
| 7 | +def print_ascii_art(): |
| 8 | + ascii_art = """ |
| 9 | + _____ |
| 10 | + .-' `-. |
| 11 | + .' `. |
| 12 | + / _.._ _.._ \\ |
| 13 | + | / \\ / \\ | |
| 14 | + | \\ / \\ / | |
| 15 | + \\ `--' `--' / |
| 16 | + `. .' |
| 17 | + `-._ _.-' |
| 18 | + `"` |
| 19 | + Creado por DST |
| 20 | + GitHub: https://github.com/DISTinTheHouse |
| 21 | + """ |
| 22 | + print(ascii_art) |
| 23 | + |
| 24 | +print_ascii_art() |
| 25 | + |
| 26 | +PORT = 8000 |
| 27 | + |
| 28 | +# Detecta auto IP local |
| 29 | +def get_local_ip(): |
| 30 | + hostname = socket.gethostname() |
| 31 | + local_ip = socket.gethostbyname(hostname) |
| 32 | + return local_ip |
| 33 | + |
| 34 | +# IP Pública |
| 35 | +def get_public_ip(): |
| 36 | + try: |
| 37 | + response = requests.get('https://api.ipify.org?format=json') |
| 38 | + ip_data = response.json() |
| 39 | + return ip_data['ip'] |
| 40 | + except requests.RequestException as e: |
| 41 | + print(f"Error al obtener IP pública: {e}") |
| 42 | + return None |
| 43 | + |
| 44 | +# Establece la carpeta en la que estás sirviendo los archivos (en este caso, la misma que el script) |
| 45 | +DIRECTORY = "." |
| 46 | + |
| 47 | +# Crea un manejador que sirva los archivos HTML, CSS, JS en la carpeta actual |
| 48 | +class CustomHandler(http.server.SimpleHTTPRequestHandler): |
| 49 | + def __init__(self, *args, **kwargs): |
| 50 | + super().__init__(*args, directory=DIRECTORY, **kwargs) |
| 51 | + |
| 52 | + def log_message(self, format, *args): |
| 53 | + client_ip = self.client_address[0] |
| 54 | + public_ip = get_public_ip() |
| 55 | + user_agent = self.headers.get('User-Agent', 'Desconocido') |
| 56 | + accept_language = self.headers.get('Accept-Language', 'Desconocido') |
| 57 | + timezone = self.headers.get('Time-Zone', 'Desconocido') |
| 58 | + timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
| 59 | + |
| 60 | + log_entry = ( |
| 61 | + f"Timestamp: {timestamp}\n" |
| 62 | + f"IP: {client_ip}\n" |
| 63 | + f"IP Pública: {public_ip}\n" |
| 64 | + f"usuario-agente: {user_agent}\n" |
| 65 | + f"Accept-Language: {accept_language}\n" |
| 66 | + f"Time-Zone: {timezone}\n" |
| 67 | + "----------------------------------------\n" |
| 68 | + ) |
| 69 | + |
| 70 | + # Registra detalles en un archivo .txt |
| 71 | + with open("access_log.txt", "a") as log_file: |
| 72 | + log_file.write(log_entry) |
| 73 | + |
| 74 | + # Y en consola |
| 75 | + print(log_entry) |
| 76 | + |
| 77 | +# Obtén la IP local |
| 78 | +local_ip = get_local_ip() |
| 79 | + |
| 80 | +# Configura el servidor HTTP |
| 81 | +with socketserver.TCPServer((local_ip, PORT), CustomHandler) as httpd: |
| 82 | + print(f"Sirviendo en http://{local_ip}:{PORT}") |
| 83 | + print("Presiona Ctrl+C para detener el servidor.") |
| 84 | + # Ejecuta el servidor hasta que lo detengas manualmente |
| 85 | + httpd.serve_forever() |
0 commit comments