Skip to content

Instantly share code, notes, and snippets.

@imranbhullar
Created March 12, 2018 04:51
Show Gist options
  • Save imranbhullar/3cdedf9c24fae32341cc04f61f8a83e7 to your computer and use it in GitHub Desktop.
Save imranbhullar/3cdedf9c24fae32341cc04f61f8a83e7 to your computer and use it in GitHub Desktop.
Using pexpect to play with network appliances e.g. netscaler
import pexpect
child = pexpect.spawn ('ssh [email protected] -o StrictHostKeyChecking=no')
child.expect ('Password:')
child.sendline('mysupersecret\n')
child.expect ('.*>')
child.sendline ('show Hostname\n')
child.expect('>')
print child.before
child.expect('>')
child.sendline ('set HostName EDGE-Device\n')
child.expect('>')
print child.before
child.sendline ('show Hostname\n')
child.expect('>')
child.sendline ('save config')
child.expect('>')
child.sendline ('quit\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment