Created
April 4, 2018 18:36
-
-
Save tyler-8/50554899bf76e664c37cec67c5cd4a1d to your computer and use it in GitHub Desktop.
Parse the PortList output from SNMP OIDs like 'ieee8021QBridgeVlanCurrentEgressPorts'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parsePortList(portlist): | |
""" | |
Returns indexes of ports where | |
VLAN is present. | |
""" | |
port_status = [] | |
present_ports = [] | |
for values in portlist: | |
for i, bit in enumerate('{:08b}'.format(values)): | |
bit = int(bit) | |
if bit: | |
port_status.append(True) | |
else: | |
port_status.append(False) | |
for index, state in enumerate(port_status): | |
if state: | |
present_ports.append(index+1) | |
return present_ports |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment