async def run_multiple_clients(hosts,debug,uname,pwd,enable):
tasks = (run_client(host,debug,uname,pwd,enable) for host in hosts)
await asyncio.gather(*tasks)
def file_to_list(fname):
with open(fname, 'r') as f:
lines = [line.rstrip() for line in f]
f.close()
return lines
if __name__ == '__main__':
inputfile = ''
debugfile = ''
inputhosts=[]
debug_cli=[]
try:
opts, args = getopt.getopt(sys.argv[1:],"h:d:u:p:e:",['hosts=','debug=','uname=','pwd=','enable='])
except getopt.GetoptError as e:
print (e)
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--hosts"):
inputfile = arg
elif opt in ("-d", "--debug"):
debugfile = arg
elif opt in ("-u", "--uname"):
username = arg
elif opt in ("-p", "--pwd"):
password = arg
elif opt in ("-e", "--enable"):
enable = arg
#read the list of target ip addresses
input_hosts = file_to_list(inputfile)
#read the list of debug cli's
debug_cli = file_to_list(debugfile)
#asyncio.get_event_loop().run_until_complete(run_multiple_clients(input_hosts, debug_cli,username,password,enable))
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(run_multiple_clients(input_hosts, debug_cli,username,password,enable))
except KeyboardInterrupt:
for p in proclist:
p.stdin.write('exit\r')
time.sleep(3)
print ('Program terminated')