Advertisement
Guest User

Untitled

a guest
Aug 16th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import paramiko, time
  2.  
  3. def run_commands(ip_address, user, password, commandList, buff=5000):
  4.  
  5. print "Configuring " + ip_address
  6. client = paramiko.SSHClient()
  7. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  8. client.connect(ip_address, username=user, password=password)
  9. chan = client.invoke_shell()
  10.  
  11. if not isinstance(commandList, list):
  12. commandList = commandList.split('\n')
  13. for com in commandList:
  14. chan.send(com+'\n')
  15. time.sleep(1)
  16. output = chan.recv(buff)
  17. print output
  18. print
  19.  
  20. if __name__ == '__main__':
  21. # run_commands('50.1.1.1', 'vyos', 'vyos', ['echo $PATH'])
  22. cmds = ['echo $PATH']
  23. user = 'vyos'
  24. passwd = 'vyos'
  25. hosts = ['50.1.1.1','50.1.1.2']
  26.  
  27. for h in hosts:
  28. run_commands(h, user, passwd, cmds)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement