|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import socket |
| 3 | +import platform |
| 4 | +import subprocess |
| 5 | +import mysql.connector |
| 6 | +import psycopg2 |
| 7 | + |
| 8 | +# Configuración |
| 9 | +MARIADB_PORT = 13306 |
| 10 | +POSTGRES_PORT = 15432 |
| 11 | +MARIADB_USER = "django_user" |
| 12 | +MARIADB_PASS = "django_pass" |
| 13 | +MARIADB_DB = "ivr_legacy" |
| 14 | +POSTGRES_USER = "django_user" |
| 15 | +POSTGRES_PASS = "django_pass" |
| 16 | +POSTGRES_DB = "iact_analytics" |
| 17 | + |
| 18 | +def check_port(host, port): |
| 19 | + try: |
| 20 | + with socket.create_connection((host, port), timeout=2): |
| 21 | + return "[ESCUCHANDO]" |
| 22 | + except Exception: |
| 23 | + return "[NO DISPONIBLE]" |
| 24 | + |
| 25 | +def check_ping(host): |
| 26 | + try: |
| 27 | + output = subprocess.check_output(f"ping -n 1 {host}", shell=True, text=True) |
| 28 | + return "[OK]" if "TTL=" in output else "[FALLO]" |
| 29 | + except Exception: |
| 30 | + return "[FALLO]" |
| 31 | + |
| 32 | +def check_mysql(user, password, db=None, port=3306): |
| 33 | + try: |
| 34 | + conn = mysql.connector.connect(user=user, password=password, host="127.0.0.1", port=port, database=db) |
| 35 | + conn.close() |
| 36 | + return "[OK]" |
| 37 | + except Exception as e: |
| 38 | + return f"[FALLO] {str(e).splitlines()[0]}" |
| 39 | + |
| 40 | +def check_postgres(user, password, db=None, port=5432): |
| 41 | + try: |
| 42 | + conn = psycopg2.connect(user=user, password=password, host="127.0.0.1", port=port, dbname=db) |
| 43 | + conn.close() |
| 44 | + return "[OK]" |
| 45 | + except Exception as e: |
| 46 | + return f"[FALLO] {str(e).splitlines()[0]}" |
| 47 | + |
| 48 | +def section(title): |
| 49 | + print("\n" + "="*66) |
| 50 | + print(title) |
| 51 | + print("="*66) |
| 52 | + |
| 53 | +def main(): |
| 54 | + section("VERIFICACION DE PUERTOS Y CONEXIONES DESDE HOST WINDOWS") |
| 55 | + |
| 56 | + section("1. INFORMACION DEL SISTEMA") |
| 57 | + print(f"Hostname: {platform.node()}") |
| 58 | + print(f"Sistema: {platform.platform()}") |
| 59 | + print(f"Arquitectura: {platform.machine()}") |
| 60 | + |
| 61 | + section("2. CONECTIVIDAD BASICA") |
| 62 | + print("Loopback (127.0.0.1):", check_ping("127.0.0.1")) |
| 63 | + print("Gateway por defecto (10.0.2.2):", check_ping("10.0.2.2")) |
| 64 | + print("Internet (8.8.8.8):", check_ping("8.8.8.8")) |
| 65 | + |
| 66 | + section("3. PUERTOS REDIRECCIONADOS HACIA VM") |
| 67 | + print(f"MariaDB puerto {MARIADB_PORT}:", check_port("127.0.0.1", MARIADB_PORT)) |
| 68 | + print(f"PostgreSQL puerto {POSTGRES_PORT}:", check_port("127.0.0.1", POSTGRES_PORT)) |
| 69 | + |
| 70 | + section("4. PRUEBAS DE CONEXION A BASES DE DATOS EN VM") |
| 71 | + print(f"MariaDB ({MARIADB_USER}):", check_mysql(MARIADB_USER, MARIADB_PASS, db=MARIADB_DB, port=MARIADB_PORT)) |
| 72 | + print(f"PostgreSQL ({POSTGRES_USER}):", check_postgres(POSTGRES_USER, POSTGRES_PASS, db=POSTGRES_DB, port=POSTGRES_PORT)) |
| 73 | + |
| 74 | + section("5. RESOLUCION DNS") |
| 75 | + print("Resolucion DNS (google.com):", check_ping("google.com")) |
| 76 | + |
| 77 | +if __name__ == "__main__": |
| 78 | + main() |
0 commit comments