Telnet Python

Script which will telnet to a switch and create a new VLAN:

import getpass
import sys
import telnetlib

HOST = ‘192.168.1.1’
user = raw_input(‘Enter your telnet username: ‘)
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until(‘Login: ‘)
tn.write(user + ‘\n’)
if password:
tn.read_until(‘Password: ‘)
tn.write(password + ‘\n’)

tn.write(‘enable\n’)
tn.write(‘conf t\n’)
tn.write(‘vlan create 101 type port-mstprstp 0\n’)
tn.write(‘exit\n’)
tn.write(‘exit\n’)

 

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 )

Connecting to %s