TelnetLib does not properly close the socket

0

I'm developing a script in python that sends sms using a telnet connection to a portech mv-372.

The script works correctly but after some time the telnet connection drops and throws an "[Errno 32] Broken pipe" exception. As the script is running as a systemd service every time I find an error I end the script and systemd restarts it.

When the script reboots it goes into a loop because it can not connect to the modem over telnet. The script only reconnects when I reboot the modem.

Here's an excerpt of the code:

# Creare a Telnet Connection to Host1
try:
    tn = telnetlib.Telnet(HOST)
    sleep(1)
    tn.read_until('username: ')
    SendCommandToSocket(USERNAME, "password: ", 10, tn)
    SendCommandToSocket(PASSWORD, "info.\r\n]", 10, tn)
    print "Connection Established"
except Exception as e:
    print e
    logger.critical('Cannot connect to socket. Exception is: %s' %e)
    tn.close()
    sleep(10)
    exit()

Before tcerminar the script I always close the onexao telnet using tn.close ().

Does anyone know why the link is blocked after the script finishes?

    
asked by anonymous 09.05.2017 / 15:35

1 answer

0

Can you do a package analysis? Try to use tcpdump or wireshark to do an analysis of the point that happens and then is being rejected. It looks like your script is sending a packet and it is getting a reset. tcpdump -nvtttS iphost if you want to save add .... -Z $ USER -w save.dump

Surely an analysis will give you a feel for what's happening.

    
09.12.2017 / 01:49