First of all sorry for my bad English.
I made a script that connects to a Mikortik RB750 and executes commands by SSH. When I run it (without compiling), it works well and meets the objective. The problem I'm having is that when I try to compile it on Windows fails. Works fine until it try to run the SSH connection.
I'm trying to compile it using the command python -m py2exe.build_exe ssh_menu.py
It tells me that 4 modules are missing: UserDict; gssapi; packaging; readline.
I have no idea how to solve this, and I google a lot, pitifully this is the first time that I attempt to do something with python and I’m lost now.
Here is my code:
import os
import sys
import time
import select
import paramiko
server, username, password = ('192.168.88.1', 'admin', '976431')
comando1=" "
comando2=" "
ipUbicacion=" "
flagUbicacion=True
ipSalida=" "
flagSalida=True
addresList1=" "
miIp=input("Cual es su dirección IP: ")
while flagUbicacion:
print("""
1.ESSO Centro
2.ESSO Rotonda
3.Casa Don Oscar / Sebastian
4.Transporte Garay
5.Salir
""")
idUbicacion=input("Cual es su ubicación? ")
if idUbicacion=="1":
ipUbicacion="192.168.88.1"
flagUbicacion=False
elif idUbicacion=="2":
ipUbicacion="192.168.88.2"
flagUbicacion=False
elif idUbicacion=="3":
ipUbicacion="192.168.88.3"
flagUbicacion=False
elif idUbicacion=="4":
ipUbicacion="192.168.88.4"
flagUbicacion=False
elif idUbicacion=="5":
print("\n Programa Terminado")
idUbicacionans = None
else:
print("\n El dato ingresado no es valido")
while flagSalida:
print("""
1.Modem ESSO Centro
2.Integra ESSO Centro
3.Modem ESSO Rotonda
4.Modem Casa Don Oscar
5.10+ Transporte Garay
6.GampelCom Transporte Garay
7.Salir
""")
idSalida=input("Por cual puerta de enlace quiere salir? ")
if idSalida=="1":
ipSalida="192.168.88.1"
auxUbicacion="1"
flagSalida=False
elif idSalida=="2":
ipSalida="192.168.88.1"
auxUbicacion="1"
flagSalida=False
elif idSalida=="3":
ipSalida="192.168.88.2"
auxUbicacion="2"
flagSalida=False
elif idSalida=="4":
ipSalida="192.168.88.3"
auxUbicacion="3"
flagSalida=False
elif idSalida=="5":
ipSalida="192.168.88.4"
auxUbicacion="4"
flagSalida=False
elif idSalida=="6":
ipSalida="192.168.88.4"
auxUbicacion="4"
flagSalida=False
elif idSalida=="7":
print("\n Programa Terminado")
idSalida = None
flagSalida=False
else:
print("\n El dato ingresado no es valido")
if ipUbicacion==ipSalida:
cantComandos=1
else:
cantComandos=2
i=0
while i<cantComandos:
if idUbicacion=="1": #SI ESTOY EN LA ESSO DEL CENTRO Y...
if idSalida=="1": #...QUIERO SALIR POR EL MODEM
addresList1="WAN1"
elif idSalida=="2": #...QUIERO SALIR POR EL INTEGRA
addresList1="WAN2"
elif idSalida=="3": #...QUIERO SALIR POR RB_ROTONDA
addresList1="WAN3"
elif idSalida=="4": #...QUIERO SALIR POR RB_OSCAR
addresList1="WAN4"
elif idSalida=="5": #...QUIERO SALIR POR RB_TRANSPORTE
addresList1="WAN5"
elif idSalida=="6": #...QUIERO SALIR POR RB_TRANSPORTE
addresList1="WAN5"
if idUbicacion=="2": #SI ESTOY EN LA ESSO DE LA ROTONDA Y...
if idSalida=="1": #...QUIERO SALIR POR RB_CENTRO
addresList1="WAN2"
elif idSalida=="2": #...QUIERO SALIR POR RB_CENTRO
addresList1="WAN2"
elif idSalida=="3": #...QUIERO SALIR POR MODEM ROTONDA
addresList1="WAN1"
elif idSalida=="4": #...QUIERO SALIR POR RB_OSCAR
addresList1="WAN3"
elif idSalida=="5": #...QUIERO SALIR POR RB_TRANSPORTE
addresList1="WAN4"
elif idSalida=="6": #...QUIERO SALIR POR RB_TRANSPORTE
addresList1="WAN4"
if idUbicacion=="3": #SI ESTOY EN LA CASA DE OSCAR Y...
if idSalida=="1": #...QUIERO SALIR POR RB_CENTRO
addresList1="WAN2"
elif idSalida=="2": #...QUIERO SALIR POR RB_CENTRO
addresList1="WAN2"
elif idSalida=="3": #...QUIERO SALIR POR RB_ROTONDA
addresList1="WAN3"
elif idSalida=="4": #...QUIERO SALIR POR MODEM OSCAR
addresList1="WAN1"
elif idSalida=="5": #...QUIERO SALIR POR RB_TRANSPORTE
addresList1="WAN4"
elif idSalida=="6": #...QUIERO SALIR POR RB_TRANSPORTE
addresList1="WAN4"
if idUbicacion=="4": #SI ESTOY EN TRANSPORTE Y...
if idSalida=="1": #...QUIERO SALIR POR RB_CENTRO
addresList1="WAN3"
elif idSalida=="2": #...QUIERO SALIR POR RB_CENTRO
addresList1="WAN3"
elif idSalida=="3": #...QUIERO SALIR POR RB_ROTONDA
addresList1="WAN4"
elif idSalida=="4": #...QUIERO SALIR POR RB_OSCAR
addresList1="WAN5"
elif idSalida=="5": #...QUIERO SALIR POR 10+ TRANSPORTE
addresList1="WAN1"
elif idSalida=="6": #...QUIERO SALIR POR GAMPELCOM TRANSPORTE
addresList1="WAN2"
if i==0:
server=ipUbicacion
while True:
print ("Conectando a "+server+": Intento "+repr(i)+" de 10")
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server, username=username, password=password)
print ("Conectado a "+server)
break
except paramiko.AuthenticationException:
print ("Fallo de autentificación conectando a "+server)
except:
print ("Fallo de SSH en "+server+", esperando que se inicie")
i += 1
time.sleep(1)
if i == 10:
print ("No se pudo conectar a "+server+". Conexión cancelada") % server
ssh.exec_command('ip firewall address-list remove [find where address="'+miIp+'"]')
ssh.exec_command('ip firewall address-list add list="'+addresList1+'" address="'+miIp+'"')
print('ip firewall address-list add list="'+addresList1+'" address="'+miIp+'"')
print ("Comando ejecutado, cerrando conexión SSH")
ssh.close()
time.sleep(1)
else:
server=ipSalida
while True:
print ("Conectando a "+server+": Intento "+repr(i)+" de 10")
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server, username=username, password=password)
print ("Conectado a "+server)
break
except paramiko.AuthenticationException:
print ("Fallo de autentificación conectando a "+server)
except:
print ("Fallo de SSH en "+server+", esperando que se inicie")
i += 1
time.sleep(1)
if i == 10:
print ("No se pudo conectar a "+server+". Conexión cancelada") % server
ssh.exec_command('ip firewall address-list remove [find where address="'+miIp+'"]')
ssh.exec_command('ip firewall address-list add list="'+addresList1+'" address="'+miIp+'"')
print('ip firewall address-list add list="'+addresList1+'" address="'+miIp+'"')
print ("Comando ejecutado, cerrando conexión SSH")
ssh.close()
time.sleep(1)
idUbicacion=auxUbicacion
i=i+1