1

I want to pull all the MAC addresses that the switch knows about. I found in SNMPv2

This command is successful from a linux terminal

snmpwalk -v2c  -c SNMPCommunity@10 10.10.10.10 .1.3.6.1.2.1.17.4.3.1.1

This command needs to have the "@10" inserted but I have no idea where.

snmpwalk -v3  -l authPriv -u username -a SHA -A authpriv  -x DES -X authkey 10.10.10.10 .1.3.6.1.2.1.17.4.3.1.1

The above command only pulls MAC addresses from VLAN1. I tried username@10 - but then I get bad username

Big picture. I'm trying to pull them with a python script using pysnmp. I got everything working but this last part.

Dwight
  • 15
  • 6
  • I'm getting closer. I added "snmp-server group snmpgroupname v3 auth context vlan- match prefix" to the cisco config. Now I can get a vlan mac return from "snmpwalk -v 3 -l authPriv -u testUser -a MD5 -A testv3 -x 3DES -X testpriv3DES –n vlan-10 " yay - my question is answered, but I can't get pysnmp to pass the contextname. Maybe that's a different question. – Dwight Jul 17 '19 at 01:36
  • Your question is tagged pysnmp but your examples are for Net-SNMP from the command line. Which are you actually using? – Lightness Races in Orbit Jul 17 '19 at 13:26
  • oops. I can't post the pysnmp code in the comment box (too long) but I have crossposted the questoion here https://github.com/etingof/pysnmp/issues/284 – Dwight Jul 18 '19 at 01:43
  • Construct then post a [mcve]. And put it in the question, not in the comments. – Lightness Races in Orbit Jul 18 '19 at 10:59
  • @Dwight, I am trying to do the same thing, but adding Contextname is not returning anything, how did you get yours done? – Ahmad_R Apr 15 '21 at 17:31
  • @ahmad_r According to my comment on the answer "below" I added ContextData(contextName='vlan-10'). I think this was on Cisco 3850 switches, probably running 15.2 code or similar. – Dwight Apr 16 '21 at 18:19
  • https://stackoverflow.com/questions/67115981/pysnmp-pulling-mac-address-table-per-vlan-on-cisco-switch-with-snmpv3 ---- I have done what you did but i am getting error, i have posted the question on the link. i am not sure what i am doing wrong. – Ahmad_R Apr 16 '21 at 18:23

1 Answers1

0

To get pysnmp using non-default SNMP context name, just pass your context name in form of ContextName object as contextData parameter to nextCmd().

from pysnmp.hlapi import *

errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(),
           UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
           UdpTransportTarget(('demo.snmplabs.com', 161)),
           ContextData(contextName='vlan-10'),
           ObjectType(ObjectIdentity('1.3.6.1.2.1.17.4.3.1.1')))
)
Ilya Etingof
  • 5,440
  • 1
  • 17
  • 21