I have a small script that will check to see if a list of devices are either ssh or telnet enable. Here is my code:
import socket
import sys
file = open('list', 'r')
file = file.readlines()
list = []
for i in file:
i=i.replace('\n','')
list.append(i)
for i in list:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((i, 22))
s.shutdown(2)
s.close()
print (i+' SSH ')
except:
try:
s.connect((i, 23))
s.shutdown(2)
s.close()
print (i+' Telnet')
except:
print (i + 'disable')
pass
When I get an exception, I have to hit ctrl + c to go to the next device. What are am I doing wrong? Thanks