Skip to content

GNS3 Talks: Python for Network Engineers with GNS3 (Part 5) - Multiple switches, multiple VLANs - ISSUE #14

Description

@moodhacker

Hello David. Any reason why this only configure one switch? I am able to telnet from my SW1 to all the devices and also from my home laptop that run the script. Every time I ran it, it only configure SW4, if I reduce the range, it will take any of the random SW

#!/usr/local/bin/python3.9

import getpass
import sys
import telnetlib

user = input("Enter your telnet user name: ")
password = getpass.getpass()

for n in range (10,14):
HOST = "10.115.0." + str(n)
tn = telnetlib.Telnet(HOST)

tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
    tn.read_until(b"Password: ")
    tn.write(password.encode('ascii') + b"\n")

tn.write(b"config t\n")

for n in range(2,11):
     tn.write(b"vlan " + str(n).encode('ascii') + b"\n")
     tn.write(b"name Python_VLAN_" + str(n).encode('ascii') + b"\n")

tn.write(b"end\n")
tn.write(b"write\n")
tn.write(b"exit\n")

print(tn.read_all().decode('ascii'))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions