davidbombal / pythonvideos

Code examples for David Bombal's Python Videos
419 stars 221 forks source link

did not get last host #4

Open vietde opened 6 years ago

vietde commented 6 years ago

Hi David,

I used your script but doesn't do telnet all host. Please check my error:

oot@NetworkAutomation-1:~# ./pythonloopscript Enter your telnet username: username Password: Telnet to host36 Telnet to host37 Telnet to host38

here is my script:

!/usr/bin/env python

import getpass import sys import telnetlib

user = raw_input("Enter your telnet username: ") password = getpass.getpass()

for n in range (36,39): print ("Telnet to host") + str(n) HOST = "192.168.13." + str(n) tn = telnetlib.Telnet(HOST)

tn.read_until("Username: ") tn.write(user + "\n")

if password: tn.read_until("Password: ") tn.write(password + "\n")

tn.write("conf t\n")

for n in range (2,21): tn.write("no banner exec ^C " + "\n") tn.write("no banner incoming ^C " + "\n") tn.write("no banner login ^C " + "\n") tn.write("no vlan " + str(n) + "\n")

Thanks.

sudharshans-s commented 6 years ago

Change "for n in range (36,39):" to "for n in range (36,40):"