[Python] Python Telnetlib conectar a porta diferente da 23 [fechada]

Discussão em 'Python' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    Olá;

    Estou tentando fazer um script em python para conectar na porta 12612 do localhost. Rodando o comando telnet no linux, de forma manual, o mesmo executa. Porém, no meu script python, utilizando a biblioteca telnetlib, aparentemente não está conectando. Preciso conectar no console do telnet, e executar algumas tarefas. Segue o código:

    import os, glob, telnetlib, time

    CAMINHO = "/home/admin/deploy"
    HOST = "localhost"
    PORT = "12612"
    TIMEOUT = 2
    filename = os.path.basename(__file__)
    os.chdir(CAMINHO)

    try:
    tn = telnetlib.Telnet(HOST, PORT, TIMEOUT)
    tn.set_debuglevel('DEBUG')
    tn.open(HOST, PORT, TIMEOUT)
    except ValueError:
    print("Falha ao conectar")

    for file in glob.glob("*.jar"):
    arquivoAtual = file.split('_')[0]
    comando = ("file://" + CAMINHO + "/" + file).strip()
    tn.write(("uninstall " + arquivoAtual + "\n"))
    tn.write("install " + comando + "\n")
    tn.write("setbsl 5" + arquivoAtual + "\n")
    tn.write("start " + arquivoAtual + "\n")


    tn.write("exit" + "\n")
    tn.close()
    print('Concluido')

    Continue reading...

Compartilhe esta Página