I have a bunch of devices that I have to do an script to know if telnet is enable or not. So I did the following script:
import socket
file = open('list', 'r')
file = file.readlines()
list = []
port = 23
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
for i in file:
i=i.replace('\n','')
list.append(i)
for i in host:
try:
s.connect((i, port))
s.shutdown(2)
print (i+' Telnet is enable')
except:
print (i+' Telnet is disable')
The problem is that after the first test that show telnet is enable, all of the devices are showing as been disable. I check the error that I get and the error is the following:
socket.error: (133, 'Transport endpoint is already connected')
I know that has to do with closing the first session, but I'm not able to. Thanks in advance
closethe connection?s = socket.socket(...inside the loop.