What would be the easiest was to accomplish this?

Find all ports that do not have 'switchport port-security'

show run | exclude ?

I don't have a swicth with me and packet tracer does not have the commands avaliable.

  • Are you fluent in vi? – dan Mar 1 '15 at 15:41
  • Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer. – Ron Maupin Aug 9 '17 at 23:11

Another option if you're willing to use a python script, use ciscoconfparse.find_parents_wo_child().

In your case, usage would be:

from ciscoconfparse import CiscoConfParse

parse = CiscoConfParse('/path/to/configuration/file')
missing = parse.find_parents_wo_child('^interface', 'switchport port-security$')
for intf in missing:

Save that script to a file and run it (after you install ciscoconfparse). That script will print interfaces without port-security.

This is the github link to the library: ciscoconfparse

Full disclosure: I am the author of the library


I can't see a way to make exclude work in this situation.

You could try something like the below which will show all the interfaces port-security lines (you would just need to find interfaces with none of those - i.e. where you have two interface lines in a row):

 show run | include (^interface|port-security)

Or, if this is the specific case you are trying to achieve, a simple show port-security will list all the ports that have port-security enabled.

  • Starting with your include command, you might put the result in a file. From there with vi write a macro which will join any line prior one containing port-security. Finally remove all the lines containing port-security. The remaining lines are the ports without port-security. – dan Mar 1 '15 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.