Find Free Switchports

Cisco - Enterprise


tl;dr

Copy and paste this into your switch, just don't forget about Clive in accounts that takes the summer off!

 
show int | i proto.*notconnect|proto.*administratively down|Last in.* [6-9]w|Last in.*[0-9][0-9]w|[0-9]y|disabled|Last input never, output never, output hang never
					

What's this for?

Finding Free Switchports can be done with a not-so-simple show command you can quickly drop into a switch to find free switchports. This is really useful when an second line (and somes times 3rd line because I have nothing against the guys and girls in 2nd line!) engineer comes up to you and goes, "Ah, yeah, see now, I've looked at that switch and it's full so we will need to put a new one in!" I try hard not to but I normally turn around and say "So thats 1x Catalyst 9300, with licencing thats about £8000, can I start with the long number that goes acoss the middle of the card please.

The purpose of this command is to give you somthing to drop into your CLI quickly to find out if there is any cables you can go and remove to free up some switchports. The reality, depending on the size of your stack and how disciplined your engineers are you will find more than you need! Warning Clive in accounts has his priorities right, he tends to take the 6 week summer holiday off to spend with his kids. Think about your business enviroment when using this script it might not always be appropiate. For example I currently work in a University and come the end of August if I ran this script I would remove almost all our patches, come Septermber I would be putting them all back!

Demo Enviroment

The outputs below come from the following setup...

  • Hardware: Cisco Catalyst 9300
  • OS: IOS-XE
  • Version: 16.6.5
  • Date: 07-08-2019

Note: I have used this on all sorts of IOS and IOS-XE switches i will be supprised if you find one where it doesnt work!

:

How to find free switchports.

Going back to networking 101 you will remember the really useful command "show interface". In the guide we are going to leverage the power of this command along with the pipe command to strip out the bits were not interested in (most of the command).

Before starting it might be good to be aware of the switches' up time. If you are really struggling to find ports that haven't been used for more than 6 weeks and the switch has only been up to 2 weeks this knoledge might help you! After this put the show command in and observe the output. Noting the following:

switch#show ver | i uptime
switch uptime is 6 weeks, 6 days, 23 hours, 26 minutes
switch#
nanai-csw01#show int | i proto.*notconnect|proto.*administratively down|Last in.* [6-9]w|Last in.*[0-9][0-9]w|[0-9]y|disabled|Last input never, output never, output hang
 never
GigabitEthernet1/0/1 is administratively down, line protocol is down (disabled) 
  Last input never, output never, output hang never
GigabitEthernet1/0/2 is down, line protocol is down (notconnect) 
  Last input never, output never, output hang never
GigabitEthernet1/0/7 is down, line protocol is down (notconnect) 
  Last input never, output never, output hang never
GigabitEthernet1/0/8 is down, line protocol is down (notconnect) 
GigabitEthernet1/0/9 is down, line protocol is down (notconnect) 
GigabitEthernet1/0/10 is down, line protocol is down (notconnect) 
  Last input never, output never, output hang never
GigabitEthernet1/0/11 is down, line protocol is down (notconnect) 
  Last input never, output never, output hang never
GigabitEthernet1/0/12 is down, line protocol is down (notconnect) 
  Last input never, output never, output hang never
GigabitEthernet1/0/13 is down, line protocol is down (notconnect) 
  Last input never, output never, output hang never
GigabitEthernet1/0/14 is down, line protocol is down (notconnect) 
  Last input never, output never, output hang never
GigabitEthernet1/0/15 is down, line protocol is down (notconnect) 
  Last input never, output never, output hang never
GigabitEthernet1/0/16 is down, line protocol is down (notconnect) 
  Last input never, output never, output hang never

---Output Truncated---