ssh_by_list

import subprocess
import time

#this is the IP LIST file name and path
IPLIST = 'd:/iplist.txt'

#this is the log file location
LOGFILE = 'd:/iplistlog.txt'


def _connect(b,fh2):
    try:
        subprocess.run(b,shell = None,timeout = 5,)
        #l1 = subprocess.getoutput([b,'timeout = 5'])
        #l2 = str(l1)
        #fh2.write(l1)
    except Exception as err:
        print(err)
        fh2.write(str(err))

    return

fh = open(IPLIST)
fh2 = open(LOGFILE,'a')
t = time.localtime()
ti = str(t[0])+'-'+str(t[1])+'-'+str(t[2])+' '+str(t[3])+':'+str(t[4])+':'+str(t[5])
count = 0
fh2.write('==='+ti+'===')
i = 0
for line in fh:
    a = 'putty -pw jasontest jasontest%s@'%str(i)
    i += 1
    b = a+line
    b = b.strip('\n')
    print(count,'-->ssh: ',line)
    fh2.write('ssh:'+line)
    _connect(b,fh2)
    count += 1
fh.close()
fh2.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当你在尝试通过SSH连接远程机器时,如果出现"ssh_exchange_identification: Connection closed by remote host"或"Connection refused"的提示,这可能是由于以下原因导致的。 首先,可能是由于远程服务器阻止了SSH连接的尝试。这可能是由于安全设置或防火墙规则导致的。你可以尝试通过其他Linux云主机使用"ssh xx@ip -pport"命令登录该云主机,如果仍然失败并出现"ssh_exchange_identification: Connection closed by remote host"的错误提示,那么很可能是远程服务器阻止了连接。\[1\]\[2\] 其次,可能是由于远程服务器突然关闭了TCP流导致的。在大多数情况下,远程服务器的快速重启可能会解决临时中断或连接问题。此外,还有可能是基于主机的访问控制列表或入侵防御软件(如Fail2ban、DenyHosts等)通过更新防火墙规则来阻止了IP对SSH守护程序的访问。\[3\] 为了解决这个问题,你可以尝试以下方法: 1. 检查远程服务器的防火墙设置,确保SSH连接被允许通过。 2. 如果你有其他可用的登录方式(如控制台或远程桌面),尝试重启远程服务器。 3. 检查是否有任何入侵防御软件(如Fail2ban、DenyHosts)在阻止SSH连接。如果有,可以尝试修改其配置文件或暂时禁用它们。 4. 如果问题仍然存在,你可以联系远程服务器的管理员或技术支持寻求进一步的帮助。 总结起来,当出现"ssh_exchange_identification: Connection closed by remote host"或"Connection refused"的错误提示时,可能是由于远程服务器阻止了SSH连接的尝试或远程服务器突然关闭了TCP流导致的。你可以尝试检查防火墙设置、重启远程服务器、检查入侵防御软件的配置或寻求进一步的帮助来解决这个问题。 #### 引用[.reference_title] - *1* *2* [ssh登录失败,报:ssh_exchange_identification read Connection reset](https://blog.csdn.net/KEYMA/article/details/127500279)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [解决 ssh_exchange_identification 问题](https://blog.csdn.net/Double_Horse/article/details/131186707)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值