猿问

Python Try and Except-脚本被挂在except上

我有一个小脚本,该脚本将检查设备列表是否为ssh或telnet enable。这是我的代码:


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才能转到下一个设备。我在做什么错?谢谢


慕哥6287543
浏览 150回答 3
3回答
随时随地看视频慕课网APP

相关分类

Python
我要回答