Pexpect Script

Mastering Python Networking (Pexpect).

import getpass
from pexpect import pxssh
import time

devices = {‘VSP-8284XSQ-1’: {‘prompt’: ‘VSP-8284XSQ-1:1>’, ‘ip’: ‘’}, ‘VSP-8284XSQ-2’: {‘prompt’: ‘VSP-8284XSQ-2:1>’, ‘ip’: ‘’}}

commands = [‘terminal more disable’, ‘show sys-info card’, ‘terminal more enable’]

username = input(‘Username: ‘)
password = getpass.getpass(‘Password: ‘)

for device in devices.keys():
outputFileName = device + ‘_output.txt’
device_prompt = devices[device] [‘prompt’]
device_ip = devices[device] [‘ip’]
child = pxssh.pxssh()
child.login(devices[device] [‘ip’], username.strip(), password.strip(), auto_prompt_reset=False)
print(‘Logged in to ‘ + device)
with open(outputFileName, ‘wb’) as f:
for command in commands:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s