Multiple ssh login Python-Paramiko with threading

import socket
socket.setdefaulttimeout(5)

import paramiko
import sys
import threading
import os
import time

ipaddresses = []
f=open('add1.csv','r').readlines()
fw = open('logins.csv', 'a')
ipaddresses = f
user = 'test'
passwd = 'helloworld'

def trylogin(ipaddress):
	global user,passwd
	
	ssh = paramiko.SSHClient()
	ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
	try:
		ssh.connect(ipaddress,username=user,password=passwd)
	except paramiko.AuthenticationException:
		print "[-] Authentication Exception! ..."		
		
	except paramiko.SSHException:
		print "[-] SSH Exception! ..."	
		
	works = ipaddress.strip('\n')+','+user+','+passwd	
	print '[+] '+ works
	fw.write(works+'\n')

try:
	count=0
	while count<len(ipaddresses):
			for i in xrange(5):
					threading.Thread(target=trylogin,args=(str(ipaddresses[count]),)).start()
					time.sleep(0.7)
					count+=1
except Exception, e:
		print '[-] General Exception'

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s