Skip to content

Instantly share code, notes, and snippets.

@bDrwx
Last active June 17, 2019 20:06
Show Gist options
  • Save bDrwx/36a2cd038d135826d5da9b0d71f8a8ec to your computer and use it in GitHub Desktop.
Save bDrwx/36a2cd038d135826d5da9b0d71f8a8ec to your computer and use it in GitHub Desktop.
Simple example
import getpass
import sys
import re
from netmiko import ConnectHandler
pattern = re.compile(r'Huawei\s\w+\s\w+\suptime')
COMMAND = sys.argv[1]
USER = input('Username: ')
PASSWORD = getpass.getpass()
DEVICES_IP = ['192.168.1.2']
for IP in DEVICES_IP:
print('Connection to device {}'.format(IP))
DEVICES_PARAMS = {'device_type': 'huawei',
'ip': IP,
'username': USER,
'password': PASSWORD}
with ConnectHandler(**DEVICES_PARAMS) as ssh:
ssh.enable()
result = pattern.findall(ssh.send_command('display version'))
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment