Python script to take telnet of CISCO device

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

import os
import telnetlib

host  = ""
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')


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


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: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s