PySNMP cannot recognize the response

I am using the following simple script:

from pysnmp.entity.rfc3413.oneliner import cmdgen

errorIndication, errorStatus, errorIndex, \
varBindTable = cmdgen.CommandGenerator().bulkCmd(
            cmdgen.CommunityData('test-agent', 'public'),
            cmdgen.UdpTransportTarget(('IP.IP.IP.IP', 161)),
            0,
            1,
            (1,3,6,1,2,1,4,24,4,1,2,169,254)
        )

if errorIndication:
   print errorIndication
else:
    if errorStatus:
        print '%s at %s\n' % (
            errorStatus.prettyPrint(),
            errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
            )
    else:
        for varBindTableRow in varBindTable:
            for name, val in varBindTableRow:
                print '%s = %s' % (name.prettyPrint(), val.prettyPrint())

Using snmpwalk from the command line to this device returns the expected result. But the script returns an SNMP response received before the timeout. If I omit this OID, then everything works fine. So the problem is this OID

Here is the tcpdump stats:

/usr/sbin/tcpdump -nn -vv -s0 -A host HOST and udp

tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes

12:15:31.494920 IP (tos 0x0, ttl  64, id 0, offset 0, flags [DF], proto: UDP (17), length: 77) IP.IP.IP.IP.47911 > IP.IP.IP.IP.161: [bad udp cksum 4b7d!]  { SNMPv2c { GetBulk(34) R=8993731  N=0 M=1 .1.3.6.1.2.1.4.24.4.1.2.169.254 } }
E..M..@.@.I..]<..]</.'...9.S0/.....public."....;.......0.0...+..........).~..

12:15:31.495666 IP (tos 0x0, ttl  64, id 0, offset 0, flags [DF], proto: UDP (17), length: 98) IP.IP.IP.IP.161 > IP.IP.IP.IP.47911: [udp sum ok]  { SNMPv2c { GetResponse(55) R=8993731  .1.3.6.1.2.1.4.24.4.1.2.169.254.0.0.0.0.255.255.0.0.0.0.0=[inetaddr len!=4]0.0.255.255.0.0.0.0 } }
E..b..@.@.I..]</.]<....'.N.\0D.....public.7....;.......0)0'..+..........).~.............@.........

12:15:32.500226 IP (tos 0x0, ttl  64, id 0, offset 0, flags [DF], proto: UDP (17), length: 77) IP.IP.IP.IP.47911 > IP.IP.IP.IP.161: [bad udp cksum 4b7d!]  { SNMPv2c { GetBulk(34) R=8993731  N=0 M=1 .1.3.6.1.2.1.4.24.4.1.2.169.254 } }
E..M..@.@.I..]<..]</.'...9.S0/.....public."....;.......0.0...+..........).~..

12:15:32.500624 IP (tos 0x0, ttl  64, id 0, offset 0, flags [DF], proto: UDP (17), length: 98) IP.IP.IP.IP.161 > IP.IP.IP.IP.47911: [udp sum ok]  { SNMPv2c { GetResponse(55) R=8993731  .1.3.6.1.2.1.4.24.4.1.2.169.254.0.0.0.0.255.255.0.0.0.0.0=[inetaddr len!=4]0.0.255.255.0.0.0.0 } }
E..b..@.@.I..]</.]<....'.N.\0D.....public.7....;.......0)0'..+..........).~.............@.........

As we can see, the device returns a response .1.3.6.1.2.1.4.24.4.1.2.169.254.0.0.0.0.255.255.0.0.0.0.0=[inetaddr len!=4]0.0.255.255.0.0.0.0, but nothing happens, and pysnmp just keeps repeating the value of this OID again and again .. snmpwalk recognizes this answer asIP ADDRESS 0.0.255.255

Can you guys help me? Thanks in advance and sorry for my English.

+5
source share
1 answer

SNMP-, , SNMP-. IPv4 , .

RFC- SNMP, pysnmp SNMP .

pysnmp IP-, IpAddress , :

>>> def ipAddressPrettyIn(self, value):
...   return origIpAddressPrettyIn(self, value[:4])
...
>>> origIpAddressPrettyIn = v2c.IpAddress.prettyIn
>>> v2c.IpAddress.prettyIn = ipAddressPrettyIn
>>>
>>> msg, rest = decoder.decode(wholeMsg, asn1Spec=v2c.Message())
>>> print msg.prettyPrint()
Message:
version='version-2'
 community=public
 data=PDUs:
 response=ResponsePDU:
  request-id=6564368
  error-status='noError'
  error-index=0
  variable-bindings=VarBindList:
   VarBind:
    name=1.3.6.1.2.1.4.24.4.1.2.169.254.0.0.0.0.255.255.0.0.0.0.0
    =_BindValue:
     value=ObjectSyntax:
       application-wide=ApplicationSyntax:
       ipAddress-value=0.0.255.255
+4

All Articles