test_cisco_w_key.py 879 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. from netmiko import ConnectHandler
  4. from os import path
  5. def main():
  6. try:
  7. hostname = raw_input("Enter remote host to test: ")
  8. except NameError:
  9. hostname = input("Enter remote host to test: ")
  10. home_dir = (path.expanduser('~'))
  11. key_file = "{}/.ssh/cisco_rsa".format(home_dir)
  12. cisco_test = {
  13. 'ip': hostname,
  14. 'username': 'testuser2',
  15. 'device_type': 'cisco_ios',
  16. 'use_keys': True,
  17. 'key_file': key_file,
  18. 'verbose': False}
  19. net_connect = ConnectHandler(**cisco_test)
  20. print()
  21. print("Checking prompt: ")
  22. print(net_connect.find_prompt())
  23. print()
  24. print("Testing show ip int brief: ")
  25. output = net_connect.send_command("show ip int brief")
  26. print(output)
  27. print()
  28. if __name__ == "__main__":
  29. main()