我有一个小脚本,可以检查设备列表是否启用了 ssh 或 telnet。这是我的代码:
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
当我遇到异常时,我必须按 ctrl + c 才能转到下一个设备。我在做什么错?谢谢