Python script to take telnet of CISCO device

Take telnet of a cisco router/switch and execute commands:

import os
import telnetlib

host  = "10.50.243.28"
user  = "username"
password = "cisco"
telnet  = telnetlib.Telnet(host)

telnet.read_until('Password: ', 3)
telnet.write(password + 'r')
telnet.write('enable' + 'rn')
telnet.write('cisco' + 'rn')
telnet.write('term len 0' + 'rn')
telnet.write("show version"+ "rn")
telnet.write('exit' + 'r')

a=telnet.read_all()

for item in a.split('n'):
        if "System serial number" in item:
                print host+'t'+item

 

Advertisements
This entry was posted in Python and tagged , , , , . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s