Skip to content

Instantly share code, notes, and snippets.

@jmacego
Last active March 1, 2019 01:47
Show Gist options
  • Save jmacego/5c2a53b216955aa1560e74af3874ea50 to your computer and use it in GitHub Desktop.
Save jmacego/5c2a53b216955aa1560e74af3874ea50 to your computer and use it in GitHub Desktop.
Script to name / interact with interfaces when ports 1-24 are plugged into the top and ports 25-48 are plugged into the bottom of a switch
#!/bin/python
from __future__ import print_function # Python 2 compatibility fix
# Script to name ports for natural patching (1 to 1, 2 to 3..25 to 2).
i = 1 # Initialize to the starting number for your port .
# Set starting number, ending number, and increment setting an increment
# of 2 is most common.
for x in range(1, 48, 2):
i += 1 # this really could to at the end and not have the -1 in the
# naming bit, but with commenting in and out stuff I like it
# better here
# Print all on the same line suitable for show int br w e 1 e 2 e 3
# print(" e 1/1/{}".format(i), end=" ")
# Print each as a second command to, for instance, name the top row of the
# first 36 ports that go to WAP patches.
print("e 1/1/{}".format(x))
print("port-name WAP{:02}".format(i - 1))
# Extend to concept to your heart's desire, I've used this script dozens of
# times like this, and countless more as various incarnations of counting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment