Created
February 19, 2014 00:47
-
-
Save jameshilliard/9084006 to your computer and use it in GitHub Desktop.
This file contains 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
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