Skip to content

Commit

Permalink
Minor fixes to SSH/telnet
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbyers committed Oct 30, 2016
1 parent d8780d7 commit 12bb044
Showing 1 changed file with 17 additions and 33 deletions.
50 changes: 17 additions & 33 deletions learnpy_ecourse/class10/main_program.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'''
"""
This is a solution to the below problem given the content we have
discussed in class. It is not necessarily the best solution to the problem.
In other words, I generally only use things we have covered up to this point
Expand Down Expand Up @@ -86,21 +85,19 @@
uptime: 8978280
serial_number: FTX1512038X
'''

"""

import time
import pickle
from getpass import getpass

import ssh_connection as ssh
import telnet_connection as telnet
from show_version_parser import process_show_version


class NetworkDevice(object):
'''
Container for network device attributes
'''
"""Container for network device attributes."""
def __init__(self, ip, username, password):
self.ip = ip
self.username = username
Expand All @@ -109,25 +106,20 @@ def __init__(self, ip, username, password):


def ssh_main():
'''
Process show version using SSH
'''

ip = '10.220.88.1'
username = 'pynet'
password = '*'
"""Process show version using SSH."""
ip = raw_input("Enter IP Address: ")
username = 'pyclass'
password = getpass()

test_device = NetworkDevice(ip, username, password)

(remote_conn_pre, remote_conn, output) = ssh.establish_connection(ip, username, password)
output = ssh.disable_paging(remote_conn)

(remote_conn_pre, remote_conn, _) = ssh.establish_connection(ip, username, password)
ssh.disable_paging(remote_conn)
remote_conn.send("\n")
remote_conn.send("show version\n")

# Read the output from the 'show version' command
test_device.show_version = ssh.read_ssh_data(remote_conn)

remote_conn_pre.close()
process_show_version(test_device)

Expand All @@ -140,18 +132,14 @@ def ssh_main():


def telnet_main():
'''
Process show version using telnet
'''

ip = '10.220.88.1'
username = 'pynet'
password = '*'
"""Process show version using telnet."""
ip = raw_input("Enter IP Address: ")
username = 'pyclass'
password = getpass()

test_device2 = NetworkDevice(ip, username, password)

remote_conn = telnet.establish_connection(ip, username, password)

telnet.disable_paging(remote_conn)

remote_conn.write("\n")
Expand All @@ -172,10 +160,7 @@ def telnet_main():


def net_device_verification(net_device):
'''
Prints out a set of attributes for a NetworkDevice object
'''

"""Prints out a set of attributes for a NetworkDevice object."""
print_attr = [
'hostname',
'ip',
Expand All @@ -193,15 +178,14 @@ def net_device_verification(net_device):
for field in print_attr:
val = getattr(net_device, field)
print "%15s: %-40s" % (field, val)

print


def main():
'''
"""
Login to a network device (using either telnet or SSH) and retrieve 'show version'
from the device.
'''
"""
print
print "Using SSH:"
ssh_main()
Expand Down

0 comments on commit 12bb044

Please sign in to comment.