Skip to content

Instantly share code, notes, and snippets.

@jameshilliard
Created February 19, 2014 00:47
Show Gist options
  • Save jameshilliard/9084006 to your computer and use it in GitHub Desktop.
Save jameshilliard/9084006 to your computer and use it in GitHub Desktop.
from pysnmp.entity.rfc3413.oneliner import cmdgen
def MACPORT(ipaddress):
cmdGen = cmdgen.CommandGenerator()
community = 'public'
errorIndication, errorStatus, errorIndex, MacTable = cmdGen.nextCmd(
cmdgen.CommunityData(community),
cmdgen.UdpTransportTarget((ipaddress, 161)),
'1.3.6.1.2.1.17.4.3.1.1',
)
errorIndication, errorStatus, errorIndex, PortTable = cmdGen.nextCmd(
cmdgen.CommunityData(community),
cmdgen.UdpTransportTarget((ipaddress, 161)),
'1.3.6.1.2.1.17.4.3.1.2',
)
macid = {}
portid = {}
macport = {}
for Rows in MacTable:
for ID, MAC in Rows:
for PortRows in PortTable:
for PortID, Port in PortRows:
#print('%s = %s' % (ID.prettyPrint(), PortID.prettyPrint()))
return(ID,PortID)
if ID == PortID:
macport[MAC] = Port
##
## for Row in MacTable:
## for ID, MAC in Row:
##
## print('%s = %s' % (ID.prettyPrint(), MAC.prettyPrint()))
##
## for Row in PortTable:
## for ID, Port in Row:
## print('%s = %s' % (ID.prettyPrint(), Port.prettyPrint()))
return macport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment