Skip to content

Instantly share code, notes, and snippets.

@tyler-8
Created April 4, 2018 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyler-8/50554899bf76e664c37cec67c5cd4a1d to your computer and use it in GitHub Desktop.
Save tyler-8/50554899bf76e664c37cec67c5cd4a1d to your computer and use it in GitHub Desktop.
Parse the PortList output from SNMP OIDs like 'ieee8021QBridgeVlanCurrentEgressPorts'
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