<filename>week2/ex2.py
#!/usr/bin/env python

import time
import telnetlib

IP = '172.16.31.10'
PORT = 23
TIMEOUT = 5

username = 'pyclass'
password = '<PASSWORD>'

def telnet_connect(ip_addr):
    return telnetlib.Telnet(IP, PORT, TIMEOUT)
    
def login(remote_conn):
    output = remote_conn.read_until('sername:', TIMEOUT)
    remote_conn.write(username + '\n')
    output = remote_conn.read_until('ssword:', TIMEOUT)
    remote_conn.write(password + '\n')
    return output

def send_command(cmd):
    remote_conn.write(cmd + "\n")
    time.sleep(1)
    return remote_conn.read_very_eager()
    
ip_addr = '172.16.31.10'

remote_conn = telnet_connect(ip_addr)
output = login(remote_conn)


cmd = 'terminal length 0'
output = send_command(cmd)


cmd = 'show ip interface brief'
output = send_command(cmd)

print output


<filename>week2/ex2.py
#!/usr/bin/env python

import time
import telnetlib

IP = '172.16.31.10'
PORT = 23
TIMEOUT = 5

username = 'pyclass'
password = '<PASSWORD>'

def telnet_connect(ip_addr):
    return telnetlib.Telnet(IP, PORT, TIMEOUT)
    
def login(remote_conn):
    output = remote_conn.read_until('sername:', TIMEOUT)
    remote_conn.write(username + '\n')
    output = remote_conn.read_until('ssword:', TIMEOUT)
    remote_conn.write(password + '\n')
    return output

def send_command(cmd):
    remote_conn.write(cmd + "\n")
    time.sleep(1)
    return remote_conn.read_very_eager()
    
ip_addr = '172.16.31.10'

remote_conn = telnet_connect(ip_addr)
output = login(remote_conn)


cmd = 'terminal length 0'
output = send_command(cmd)


cmd = 'show ip interface brief'
output = send_command(cmd)

print output


#!/usr/bin/env python