cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a simple way to see ports in a VLAN, like you can see vlan's on a port?

Is there a simple way to see ports in a VLAN, like you can see vlan's on a port?

Eric_Burke
New Contributor III

In Exos, you can issue a “show port xx vlan” to get a short, simple list of vlan’s on a port. Is there a similar way to get a brief list of ports within a vlan (as opposed to “show vlan xx”, where it’s a small block of info at the bottom? I want to see all ports in V90 for example, nothing else. Would be cool with something like “show vlan xx members”.

 

Thanks!

1 ACCEPTED SOLUTION

AdrianO
Contributor

I did a thing 

#!/usr/bin/env python
'''
Shows ports in a vlan

Tested on EXOS 22.6.1.4

Execute with:
- run script vlanports.py
or
- Make an alias: alias vlanport "run script vlanports.py"
'''

import re
import sys

exsh.clicmd('disable clipaging', False)

# Input the tag or complete name of the vlan.
if len(sys.argv) < 2:
input_tag = raw_input("Vlan: ")
else:
input_tag = sys.argv[1]

# Get vlan name
vlan_name = exsh.clicmd('show vlan {} | inc name'.format(input_tag), True)
if not vlan_name:
print 'Error: No <vlan_list> found with ID {}'.format(input_tag)
exit()
vlan_name = vlan_name.split()[4]

# Extract vlan secction of the configuration
config_lines = exsh.clicmd('show configuration vlan', True).splitlines()


# Find the first line that matches "configure vlan <vlan_name> add ports"
regex = re.compile('configure vlan {} add ports'.format(vlan_name), re.IGNORECASE)


for i, line in enumerate(config_lines):
if regex.match(line):
line_field = line.split()
print 'Ports {tag}: {ports}'.format(tag = line_field[-1], ports = line_field[5])

# If there are tagged and untagged ports configured in the vlan, the next line in the configuration has them
if regex.match(config_lines[i+1]):
line_field = config_lines[i+1].split()
print 'Ports {tag}: {ports}'.format(tag = line_field[-1], ports = line_field[5])
exit()

print 'No ports in this vlan'


9081b663ecef4158b4c20c193b890191_ff527d8e-a11b-422b-a00a-03ad1c458f5d.png

 

View solution in original post

7 REPLIES 7

Eric_Burke
New Contributor III

Perhaps a product enhancement suggestion? “show vlan vxxx members” with a tagged or untagged flag option to further narrow down the list?

BradP
Extreme Employee

Its an ugly solution, but what about “show config vlan | i “ <vlan name> add ports” ?

 

# show config vlan | i " Default add ports"
configure vlan Default add ports 1:1-7,1:9-15 untagged

 

Frank
Contributor II

Eric,

Not as far as I can tell. The only thing I could suggest is “sh vlan FOO | begin Ports:”, but that still gives you the entire “Flags” legend at the bottom

“grep” probably won’t do what you need - there can be line-breaks in the port list, grep-ing for parentheses would still include the “Flags”, and you can’t double-pipe.

I would guess someone could come up with a python script, but if there’s a better way, I’d be interested as well.

GTM-P2G8KFN