Compare commits
	
		
			No commits in common. "5b8493b67a140cada85b3174aa9260a0ca7f8fcd" and "e63a999312af82c7094b7d1ce363150197f9425e" have entirely different histories.
		
	
	
		
			5b8493b67a
			...
			e63a999312
		
	
		|  | @ -2,7 +2,6 @@ import threading | ||||||
| from models.SystemStats import SystemStats | from models.SystemStats import SystemStats | ||||||
| from MainView import MainView | from MainView import MainView | ||||||
| from models.NetworkingScanner import NetworkScanner | from models.NetworkingScanner import NetworkScanner | ||||||
| from models.Sniffer import packet_callback, sniff |  | ||||||
| import tkinter as tk | import tkinter as tk | ||||||
| import time | import time | ||||||
| import datetime | import datetime | ||||||
|  | @ -11,51 +10,13 @@ import datetime | ||||||
| class MainController: | class MainController: | ||||||
|     def __init__(self, view: MainView): |     def __init__(self, view: MainView): | ||||||
|         self.view = view |         self.view = view | ||||||
|         self.sniffer_thread = None |  | ||||||
|         self.sniffer_running = False |  | ||||||
|         self.connect_events() |         self.connect_events() | ||||||
|         self.start_system_updates() |         self.start_system_updates() | ||||||
| 
 | 
 | ||||||
|     def connect_events(self): |     def connect_events(self): | ||||||
|         """Conecta los eventos de la vista con las funciones del controlador.""" |         """Conecta los eventos de la vista con :las funciones del controlador.""" | ||||||
|         self.view.button_track_ip.config(command=self.handle_track_ip) |         self.view.button_track_ip.config(command=self.handle_track_ip) | ||||||
|         self.view.button_scan_network.config(command=self.start_network_scan_thread) |         self.view.button_scan_network.config(command=self.start_network_scan_thread) | ||||||
|         self.view.button_start_sniffer.config(command=self.start_sniffer_thread) |  | ||||||
|         self.view.button_stop_sniffer.config(command=self.stop_sniffer) |  | ||||||
|          |  | ||||||
|          |  | ||||||
|     def start_sniffer_thread(self): |  | ||||||
|         """Inicia el sniffer en un hilo separado.""" |  | ||||||
|         def run_sniffer(): |  | ||||||
|             self.sniffer_running = True |  | ||||||
|             while self.sniffer_running: |  | ||||||
|                 try: |  | ||||||
|                     sniff(prn=self.process_packet, filter="ip", store=0, timeout=1) |  | ||||||
|                 except Exception as e: |  | ||||||
|                     self.view.text_sniffer_output.insert(tk.END, f"Error: {str(e)}\n") |  | ||||||
|          |  | ||||||
|         # Configurar botones |  | ||||||
|         self.view.button_start_sniffer.config(state="disabled") |  | ||||||
|         self.view.button_stop_sniffer.config(state="normal") |  | ||||||
| 
 |  | ||||||
|         # Iniciar el hilo del sniffer |  | ||||||
|         self.sniffer_thread = threading.Thread(target=run_sniffer, daemon=True) |  | ||||||
|         self.sniffer_thread.start() |  | ||||||
|          |  | ||||||
| 
 |  | ||||||
|     def stop_sniffer(self): |  | ||||||
|         """Detiene el sniffer.""" |  | ||||||
|         self.sniffer_running = False |  | ||||||
|         self.view.button_start_sniffer.config(state="normal") |  | ||||||
|         self.view.button_stop_sniffer.config(state="disabled") |  | ||||||
|         self.view.text_sniffer_output.insert(tk.END, "Sniffer detenido.\n") |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     def process_packet(self, packet): |  | ||||||
|         """Procesa un paquete capturado y lo muestra en la interfaz.""" |  | ||||||
|         packet_info = packet_callback(packet) |  | ||||||
|         self.view.text_sniffer_output.insert(tk.END, f"{packet_info}\n") |  | ||||||
|         self.view.text_sniffer_output.see(tk.END)  # Scroll automático |  | ||||||
|          |          | ||||||
|     def start_network_scan_thread(self): |     def start_network_scan_thread(self): | ||||||
|         """Inicia un hilo para escanear la red continuamente cada 5 segundos.""" |         """Inicia un hilo para escanear la red continuamente cada 5 segundos.""" | ||||||
|  | @ -65,7 +26,7 @@ class MainController: | ||||||
|                 print("Scanning....") |                 print("Scanning....") | ||||||
|                 devices = NetworkScanner.scan_network(network_range) |                 devices = NetworkScanner.scan_network(network_range) | ||||||
|                 self.display_network_scan_results(devices) |                 self.display_network_scan_results(devices) | ||||||
|                  |                 time.sleep(1)  # Escanear cada 5 segundos | ||||||
| 
 | 
 | ||||||
|         # Inicia un hilo para el escaneo continuo |         # Inicia un hilo para el escaneo continuo | ||||||
|         threading.Thread(target=scan_network_periodically, daemon=True).start() |         threading.Thread(target=scan_network_periodically, daemon=True).start() | ||||||
|  |  | ||||||
							
								
								
									
										25
									
								
								MainView.py
								
								
								
								
							
							
						
						
									
										25
									
								
								MainView.py
								
								
								
								
							|  | @ -52,13 +52,8 @@ class MainView: | ||||||
|         self.notebook.add(tab2, text="Escaneo de Red") |         self.notebook.add(tab2, text="Escaneo de Red") | ||||||
|         self.create_network_scan_ui(tab2) |         self.create_network_scan_ui(tab2) | ||||||
| 
 | 
 | ||||||
|         # Solapa 3: Sniffer |         # Solapas 3-5: Vacías | ||||||
|         tab3 = ttk.Frame(self.notebook) |         for i in range(3, 6): | ||||||
|         self.notebook.add(tab3, text="Sniffer") |  | ||||||
|         self.create_sniffer_ui(tab3) |  | ||||||
| 
 |  | ||||||
|         # Solapas 4-5: Vacías |  | ||||||
|         for i in range(4, 6): |  | ||||||
|             tab = ttk.Frame(self.notebook) |             tab = ttk.Frame(self.notebook) | ||||||
|             self.notebook.add(tab, text=f"Solapa {i}") |             self.notebook.add(tab, text=f"Solapa {i}") | ||||||
|             label = ttk.Label(tab, text=f"Contenido de la Solapa {i}") |             label = ttk.Label(tab, text=f"Contenido de la Solapa {i}") | ||||||
|  | @ -90,22 +85,6 @@ class MainView: | ||||||
|         self.button_scan_network = ttk.Button(tab, text="Iniciar Escaneo") |         self.button_scan_network = ttk.Button(tab, text="Iniciar Escaneo") | ||||||
|         self.button_scan_network.pack(pady=5) |         self.button_scan_network.pack(pady=5) | ||||||
| 
 | 
 | ||||||
|     def create_sniffer_ui(self, tab): |  | ||||||
|         """Crea la interfaz de usuario para el sniffer en la Solapa 3.""" |  | ||||||
|         label = ttk.Label(tab, text="Sniffer de paquetes:") |  | ||||||
|         label.pack(pady=5) |  | ||||||
| 
 |  | ||||||
|         self.text_sniffer_output = scrolledtext.ScrolledText(tab, wrap=tk.WORD, height=20, width=80) |  | ||||||
|         self.text_sniffer_output.pack(fill="both", expand=True, pady=10) |  | ||||||
| 
 |  | ||||||
|         self.button_start_sniffer = ttk.Button(tab, text="Iniciar Sniffer") |  | ||||||
|         self.button_start_sniffer.pack(side="left", padx=5) |  | ||||||
| 
 |  | ||||||
|         self.button_stop_sniffer = ttk.Button(tab, text="Detener Sniffer", state="disabled") |  | ||||||
|         self.button_stop_sniffer.pack(side="left", padx=5) |  | ||||||
| 
 |  | ||||||
|      |  | ||||||
| 
 |  | ||||||
|     def create_status_bar(self): |     def create_status_bar(self): | ||||||
|         """Crea una barra de estado en la parte inferior.""" |         """Crea una barra de estado en la parte inferior.""" | ||||||
|         self.label_cpu = tk.Label(self.frame_bottom, text="Uso CPU: 0%", bg="orange", anchor="w", width=20) |         self.label_cpu = tk.Label(self.frame_bottom, text="Uso CPU: 0%", bg="orange", anchor="w", width=20) | ||||||
|  |  | ||||||
							
								
								
									
										101
									
								
								README.md
								
								
								
								
							
							
						
						
									
										101
									
								
								README.md
								
								
								
								
							|  | @ -1,101 +0,0 @@ | ||||||
| # Proyecto Kevin MultiHilo |  | ||||||
| 
 |  | ||||||
| Bienvenido al proyecto **Kevin MultiHilo**, donde exploramos y aprendemos sobre el uso de **Threads** en Python a través de diversas funcionalidades ejecutadas en hilos independientes. Este proyecto está diseñado para aquellos interesados en comprender y aprovechar la programación multihilo de manera práctica y eficiente. |  | ||||||
| 
 |  | ||||||
| --- |  | ||||||
| 
 |  | ||||||
| ## 📊 Descripción General |  | ||||||
| 
 |  | ||||||
| El objetivo principal de este proyecto es implementar tareas distribuidas en diferentes hilos, mostrando su potencial para mejorar el rendimiento y la gestión de recursos. Además, se incluyen varias dependencias y herramientas que permiten expandir las capacidades de la aplicación. |  | ||||||
| 
 |  | ||||||
| --- |  | ||||||
| 
 |  | ||||||
| ## 🔧 Dependencias |  | ||||||
| 
 |  | ||||||
| ### Dependencias Externas |  | ||||||
| 
 |  | ||||||
| - [**Nmap**](https://nmap.org/download): Herramienta potente para el escaneo de redes y auditoría de seguridad. |  | ||||||
| 
 |  | ||||||
| ### Dependencias Internas |  | ||||||
| 
 |  | ||||||
| 1. [**Scapy**](https://github.com/secdev/scapy): Permite decodificar paquetes de múltiples protocolos, enviarlos, capturarlos y analizarlos. |  | ||||||
| 2. [**os**](https://docs.python.org/es/3.10/library/os.html): Proporciona acceso a funcionalidades dependientes del sistema operativo. |  | ||||||
| 3. [**tkinter**](https://docs.python.org/es/3/library/tkinter.html): Biblioteca de interfaz gráfica predeterminada de Python. |  | ||||||
| 4. [**threading**](https://docs.python.org/es/3.8/library/threading.html): Ofrece herramientas de alto nivel para la gestión de hilos. |  | ||||||
| 5. [**time**](https://docs.python.org/3/library/time.html): Proporciona funciones relacionadas con el tiempo y la sincronización. |  | ||||||
| 6. [**datetime**](https://docs.python.org/3/library/datetime.html): Manejo avanzado de fechas y horas. |  | ||||||
| 7. [**psutil**](https://pypi.org/project/psutil/): Biblioteca para obtener información del sistema (CPU, memoria, discos, red, etc.). |  | ||||||
| 8. [**requests**](https://pypi.org/project/requests/): Simplifica el envío de solicitudes HTTP de manera eficiente. |  | ||||||
| 9. [**python-nmap**](https://pypi.org/project/python-nmap/): Biblioteca para interactuar con Nmap y manipular sus resultados. |  | ||||||
| 10. [**ipaddress**](https://docs.python.org/3/library/ipaddress.html): Manejo de direcciones y redes IPv4/IPv6. |  | ||||||
| 11. [**socket**](https://docs.python.org/3/library/socket.html): Acceso a la interfaz de sockets BSD para comunicación en red. |  | ||||||
| 
 |  | ||||||
| --- |  | ||||||
| 
 |  | ||||||
| ## 🔍 APIs Utilizadas |  | ||||||
| 
 |  | ||||||
| - [**ipwhois.io**](https://ipwhois.io/): Ofrece integración rápida y sencilla para la geolocalización de direcciones IP, ideal para scripts o sitios web. |  | ||||||
| 
 |  | ||||||
| --- |  | ||||||
| 
 |  | ||||||
| ## 🔒 Uso del Proyecto |  | ||||||
| 
 |  | ||||||
| ### Requisitos Previos |  | ||||||
| 
 |  | ||||||
| 1. Instalar Python 3.10 o superior. |  | ||||||
| 2. Descargar e instalar las dependencias necesarias utilizando **pip**: |  | ||||||
|    ```bash |  | ||||||
|    pip install -r requirements.txt |  | ||||||
|    ``` |  | ||||||
| 3. Instalar Nmap desde su [sitio oficial](https://nmap.org/download). |  | ||||||
| 
 |  | ||||||
| ### Ejecución |  | ||||||
| 
 |  | ||||||
| 1. Clonar este repositorio: |  | ||||||
|    ```bash |  | ||||||
|    git clone https://github.com/usuario/proyecto-kevin-multihilo.git |  | ||||||
|    ``` |  | ||||||
| 2. Navegar al directorio del proyecto: |  | ||||||
|    ```bash |  | ||||||
|    cd proyecto-kevin-multihilo |  | ||||||
|    ``` |  | ||||||
| 3. Ejecutar el archivo principal: |  | ||||||
|    ```bash |  | ||||||
|    python main.py |  | ||||||
|    ``` |  | ||||||
| 
 |  | ||||||
| --- |  | ||||||
| 
 |  | ||||||
| ## 📊 Características |  | ||||||
| 
 |  | ||||||
| 1. **Escaneo de redes:** Utiliza Nmap y python-nmap para descubrir dispositivos conectados. |  | ||||||
| 2. **Análisis de paquetes:** Decodificación y manejo de paquetes con Scapy. |  | ||||||
| 3. **Gestión de hilos:** Implementación eficiente de tareas paralelas con la biblioteca `threading`. |  | ||||||
| 4. **Información del sistema:** Visualización del estado actual del sistema con `psutil`. |  | ||||||
| 
 |  | ||||||
| --- |  | ||||||
| 
 |  | ||||||
| ## 🌍 Contribuciones |  | ||||||
| 
 |  | ||||||
| Si deseas contribuir a este proyecto: |  | ||||||
| 
 |  | ||||||
| 1. Realiza un fork del repositorio. |  | ||||||
| 2. Crea una rama para tus cambios: |  | ||||||
|    ```bash |  | ||||||
|    git checkout -b feature/nueva-funcionalidad |  | ||||||
|    ``` |  | ||||||
| 3. Realiza tus modificaciones y crea un pull request. |  | ||||||
| 
 |  | ||||||
| --- |  | ||||||
| 
 |  | ||||||
| ## 🎮 Autor |  | ||||||
| 
 |  | ||||||
| **Kevin Developer**\ |  | ||||||
| [GitHub](https://github.com/KevinOlarte1)  |  | ||||||
| 
 |  | ||||||
| --- |  | ||||||
| 
 |  | ||||||
| ## 📝 Tutorial |  | ||||||
| 
 |  | ||||||
| (En este apartado podrás incluir un tutorial detallado para que los usuarios aprendan a utilizar tu proyecto paso a paso.) |  | ||||||
| 
 |  | ||||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							|  | @ -1,46 +0,0 @@ | ||||||
| from scapy.all import sniff |  | ||||||
| from scapy.layers.inet import IP, TCP, UDP, ICMP |  | ||||||
| from scapy.packet import Raw |  | ||||||
| import os |  | ||||||
| import datetime |  | ||||||
| 
 |  | ||||||
| def save_packet_to_file(packet): |  | ||||||
|     """Guarda el paquete en un archivo de registro para análisis posterior.""" |  | ||||||
|     with open("packet_log.txt", "a") as log_file: |  | ||||||
|         log_file.write(f"{datetime.datetime.now()} - {packet.summary()}\n") |  | ||||||
|         log_file.write(f"{packet.show(dump=True)}\n\n") |  | ||||||
| 
 |  | ||||||
| def packet_callback(packet): |  | ||||||
|     """Procesa y retorna información del paquete capturado.""" |  | ||||||
|     packet_info = [] |  | ||||||
|     if IP in packet: |  | ||||||
|         ip_layer = packet[IP] |  | ||||||
|         packet_info.append(f"[+] Capturado un paquete:") |  | ||||||
|         packet_info.append(f"    Origen: {ip_layer.src}") |  | ||||||
|         packet_info.append(f"    Destino: {ip_layer.dst}") |  | ||||||
|         packet_info.append(f"    Protocolo: {ip_layer.proto}") |  | ||||||
| 
 |  | ||||||
|         if TCP in packet: |  | ||||||
|             tcp_layer = packet[TCP] |  | ||||||
|             packet_info.append(f"    Puerto origen: {tcp_layer.sport}") |  | ||||||
|             packet_info.append(f"    Puerto destino: {tcp_layer.dport}") |  | ||||||
|         elif UDP in packet: |  | ||||||
|             udp_layer = packet[UDP] |  | ||||||
|             packet_info.append(f"    Puerto origen: {udp_layer.sport}") |  | ||||||
|             packet_info.append(f"    Puerto destino: {udp_layer.dport}") |  | ||||||
|         elif ICMP in packet: |  | ||||||
|             packet_info.append("    Tipo de ICMP detectado.") |  | ||||||
| 
 |  | ||||||
|         if Raw in packet: |  | ||||||
|             payload = packet[Raw].load.decode(errors="ignore") |  | ||||||
|             packet_info.append(f"    Datos (Raw): {payload}") |  | ||||||
|             if "youtube.com" in payload or "YouTube" in payload: |  | ||||||
|                 packet_info.append(f"\n[!!!] Posible enlace de YouTube detectado:") |  | ||||||
|                 packet_info.append(payload) |  | ||||||
| 
 |  | ||||||
|         packet_info.append(f"[Paquete completo]: {packet.summary()}") |  | ||||||
| 
 |  | ||||||
|         # Guardar el paquete en un archivo |  | ||||||
|         save_packet_to_file(packet) |  | ||||||
| 
 |  | ||||||
|     return "\n".join(packet_info) |  | ||||||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										38906
									
								
								packet_log.txt
								
								
								
								
							
							
						
						
									
										38906
									
								
								packet_log.txt
								
								
								
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										63
									
								
								pruebas.py
								
								
								
								
							
							
						
						
									
										63
									
								
								pruebas.py
								
								
								
								
							|  | @ -11,36 +11,67 @@ def save_packet_to_file(packet): | ||||||
|         log_file.write(f"{packet.show(dump=True)}\n\n") |         log_file.write(f"{packet.show(dump=True)}\n\n") | ||||||
| 
 | 
 | ||||||
| def packet_callback(packet): | def packet_callback(packet): | ||||||
|     """Procesa y retorna información del paquete capturado.""" |     """Procesa y muestra información del paquete capturado.""" | ||||||
|     packet_info = [] |  | ||||||
|     if IP in packet: |     if IP in packet: | ||||||
|         ip_layer = packet[IP] |         ip_layer = packet[IP] | ||||||
|         packet_info.append(f"[+] Capturado un paquete:") |         print(f"\n[+] Capturado un paquete:") | ||||||
|         packet_info.append(f"    Origen: {ip_layer.src}") |         print(f"    Origen: {ip_layer.src}") | ||||||
|         packet_info.append(f"    Destino: {ip_layer.dst}") |         print(f"    Destino: {ip_layer.dst}") | ||||||
|         packet_info.append(f"    Protocolo: {ip_layer.proto}") |         print(f"    Protocolo: {ip_layer.proto}") | ||||||
| 
 | 
 | ||||||
|         if TCP in packet: |         if TCP in packet: | ||||||
|             tcp_layer = packet[TCP] |             tcp_layer = packet[TCP] | ||||||
|             packet_info.append(f"    Puerto origen: {tcp_layer.sport}") |             print(f"    Puerto origen: {tcp_layer.sport}") | ||||||
|             packet_info.append(f"    Puerto destino: {tcp_layer.dport}") |             print(f"    Puerto destino: {tcp_layer.dport}") | ||||||
|         elif UDP in packet: |         elif UDP in packet: | ||||||
|             udp_layer = packet[UDP] |             udp_layer = packet[UDP] | ||||||
|             packet_info.append(f"    Puerto origen: {udp_layer.sport}") |             print(f"    Puerto origen: {udp_layer.sport}") | ||||||
|             packet_info.append(f"    Puerto destino: {udp_layer.dport}") |             print(f"    Puerto destino: {udp_layer.dport}") | ||||||
|         elif ICMP in packet: |         elif ICMP in packet: | ||||||
|             packet_info.append("    Tipo de ICMP detectado.") |             print("    Tipo de ICMP detectado.") | ||||||
| 
 | 
 | ||||||
|         if Raw in packet: |         if Raw in packet: | ||||||
|             payload = packet[Raw].load.decode(errors="ignore") |             payload = packet[Raw].load.decode(errors="ignore") | ||||||
|             packet_info.append(f"    Datos (Raw): {payload}") |             print(f"    Datos (Raw): {payload}") | ||||||
|             if "youtube.com" in payload or "YouTube" in payload: |             if "youtube.com" in payload or "YouTube" in payload: | ||||||
|                 packet_info.append(f"\n[!!!] Posible enlace de YouTube detectado:") |                 print(f"\n[!!!] Posible enlace de YouTube detectado:") | ||||||
|                 packet_info.append(payload) |                 print(payload) | ||||||
| 
 | 
 | ||||||
|         packet_info.append(f"[Paquete completo]: {packet.summary()}") |         print(f"[Paquete completo]: {packet.summary()}") | ||||||
| 
 | 
 | ||||||
|         # Guardar el paquete en un archivo |         # Guardar el paquete en un archivo | ||||||
|         save_packet_to_file(packet) |         save_packet_to_file(packet) | ||||||
| 
 | 
 | ||||||
|     return "\n".join(packet_info) | def start_sniffer(): | ||||||
|  |     """Inicia la captura de paquetes.""" | ||||||
|  |     print("Iniciando captura de paquetes. Presiona Ctrl+C para detener.") | ||||||
|  |     print("Opciones disponibles:") | ||||||
|  |     print("1. Capturar todo el tráfico IP") | ||||||
|  |     print("2. Filtrar por TCP") | ||||||
|  |     print("3. Filtrar por UDP") | ||||||
|  |     print("4. Filtrar por ICMP") | ||||||
|  |     print("5. Salir") | ||||||
|  | 
 | ||||||
|  |     choice = input("Selecciona una opción (1-5): ") | ||||||
|  |     try: | ||||||
|  |         if choice == "1": | ||||||
|  |             sniff(prn=packet_callback, filter="ip", store=0) | ||||||
|  |         elif choice == "2": | ||||||
|  |             sniff(prn=packet_callback, filter="tcp", store=0) | ||||||
|  |         elif choice == "3": | ||||||
|  |             sniff(prn=packet_callback, filter="udp", store=0) | ||||||
|  |         elif choice == "4": | ||||||
|  |             sniff(prn=packet_callback, filter="icmp", store=0) | ||||||
|  |         elif choice == "5": | ||||||
|  |             print("Saliendo del programa.") | ||||||
|  |             return | ||||||
|  |         else: | ||||||
|  |             print("Opción no válida. Intenta de nuevo.") | ||||||
|  |             start_sniffer() | ||||||
|  |     except KeyboardInterrupt: | ||||||
|  |         print("\nCaptura detenida.") | ||||||
|  | 
 | ||||||
|  | if __name__ == "__main__": | ||||||
|  |     if os.path.exists("packet_log.txt"): | ||||||
|  |         os.remove("packet_log.txt") | ||||||
|  |     start_sniffer() | ||||||
|  | @ -1,11 +0,0 @@ | ||||||
| scapy |  | ||||||
| os |  | ||||||
| tkinter |  | ||||||
| threading |  | ||||||
| time |  | ||||||
| datetime |  | ||||||
| psutil |  | ||||||
| requests |  | ||||||
| python-nmap |  | ||||||
| ipaddress |  | ||||||
| socket |  | ||||||
		Loading…
	
		Reference in New Issue