为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕哥6287543 2021-03-28 11:07:34
我有一个小脚本,该脚本将检查设备列表是否为ssh或telnet enable。这是我的代码:import socketimport sysfile = 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才能转到下一个设备。我在做什么错?谢谢
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 149 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号