Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,65 +1,46 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import time
|
| 4 |
-
import json
|
| 5 |
|
| 6 |
-
def
|
| 7 |
try:
|
|
|
|
| 8 |
session = requests.Session()
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36",
|
| 13 |
-
"Accept": "application/json",
|
| 14 |
-
"Content-Type": "application/json"
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
# Intentar endpoints comunes de Ubiquiti
|
| 18 |
-
endpoints_try = [
|
| 19 |
-
f"http://{ip}/api/login",
|
| 20 |
-
f"http://{ip}/api/v1/login",
|
| 21 |
-
f"http://{ip}/api/v2/login",
|
| 22 |
-
f"http://{ip}/login",
|
| 23 |
-
f"https://{ip}/api/login"
|
| 24 |
-
]
|
| 25 |
-
|
| 26 |
login_data = {"username": usuario, "password": password}
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
f"http://{ip}/api/v1/device",
|
| 48 |
-
f"http://{ip}/api/v2/devices"
|
| 49 |
-
]
|
| 50 |
-
|
| 51 |
-
for status_url in status_endpoints:
|
| 52 |
-
try:
|
| 53 |
-
status_response = session.get(status_url, timeout=10, verify=False)
|
| 54 |
-
if status_response.status_code == 200:
|
| 55 |
-
metricas = status_response.json()
|
| 56 |
-
return f"""
|
| 57 |
-
# ✅ CONEXIÓN EXITOSA - {ip}
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
```json
|
| 65 |
-
{json.dumps(metricas, indent=2)[:1500]}
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import time
|
|
|
|
| 4 |
|
| 5 |
+
def test_antena(ip, usuario, password):
|
| 6 |
try:
|
| 7 |
+
# Intentar conexion HTTP simple
|
| 8 |
session = requests.Session()
|
| 9 |
|
| 10 |
+
# Probar endpoint de login
|
| 11 |
+
login_url = f"http://{ip}/api/login"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
login_data = {"username": usuario, "password": password}
|
| 13 |
|
| 14 |
+
response = session.post(login_url, json=login_data, timeout=10)
|
| 15 |
+
|
| 16 |
+
if response.status_code == 200:
|
| 17 |
+
# Login exitoso, obtener status
|
| 18 |
+
status_url = f"http://{ip}/api/v1/status"
|
| 19 |
+
status_response = session.get(status_url, timeout=10)
|
| 20 |
+
|
| 21 |
+
if status_response.status_code == 200:
|
| 22 |
+
resultado = "CONEXION EXITOSA - " + ip + "\n\n"
|
| 23 |
+
resultado += "Metricas obtenidas via API\n"
|
| 24 |
+
resultado += "Hora: " + time.strftime('%H:%M:%S')
|
| 25 |
+
return resultado
|
| 26 |
+
else:
|
| 27 |
+
return "LOGIN OK pero no se obtuvieron metricas. Status: " + str(status_response.status_code)
|
| 28 |
+
else:
|
| 29 |
+
return "ERROR DE LOGIN. Codigo: " + str(response.status_code)
|
| 30 |
+
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return "ERROR: " + str(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
# Interfaz simple
|
| 35 |
+
iface = gr.Interface(
|
| 36 |
+
fn=test_antena,
|
| 37 |
+
inputs=[
|
| 38 |
+
gr.Textbox(label="IP", value="192.168.1.24"),
|
| 39 |
+
gr.Textbox(label="Usuario", value="admin"),
|
| 40 |
+
gr.Textbox(label="Password", type="password")
|
| 41 |
+
],
|
| 42 |
+
outputs=gr.Textbox(),
|
| 43 |
+
title="Test Ubiquiti"
|
| 44 |
+
)
|
| 45 |
|
| 46 |
+
iface.launch()
|
|
|
|
|
|