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()