test_cisco_ios_serial.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. '''
  3. This will run an command via serial on an cisco ios switch and so
  4. serial cable must be attached to the device
  5. '''
  6. from __future__ import print_function
  7. from netmiko import ConnectHandler
  8. import serial
  9. def main():
  10. '''
  11. This will run an command via serial on an cisco ios switch and so
  12. serial cable must be attached to the device
  13. '''
  14. serialhandle = {
  15. 'device_type':'cisco_ios_serial',
  16. 'port': 'USB Serial', # can be COM<number> or any line you can get from
  17. # serial.tools.list_ports.comports()
  18. 'username':'<username>',
  19. 'password':'<password>',
  20. 'secret':'<secret>',
  21. 'serial_settings':{ # this are the default values
  22. 'baudrate': 9600,
  23. 'bytesize': serial.EIGHTBITS,
  24. 'parity': serial.PARITY_NONE,
  25. 'stopbits': serial.STOPBITS_ONE
  26. }
  27. }
  28. net_connect = ConnectHandler(**serialhandle)
  29. net_connect.enable()
  30. output = net_connect.send_command('show run')
  31. net_connect.disconnect()
  32. print(output)
  33. if __name__ == "__main__":
  34. main()