Python Forum

Full Version: i found my very first Python code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
while scanning through some old files in an archive, i ran across my very first Python code. i didn't know much about the language at the time. i did use the python command interactively as a calculator a lot even then. but coding this from a similar online template made me more curious what things meant and how it worked.
#!/usr/bin/env python

"""Get configuration from a Cisco router"""

import pexpect
import sys

child = pexpect.spawn('telnet 192.168.241.1')
child.expect('Password: ')

child.sendline('rumnnarb')
child.expect('#')

child.sendline('terminal length 0')
child.expect('#')

child.sendline('show running-config')
child.expect('#')
print child.before

child.sendline('exit')
child.expect('onnection closed')

if child.isalive():
    child.close()