Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant perform snmpv2-get query #140

Open
Dart-net opened this issue Apr 12, 2021 · 0 comments
Open

Cant perform snmpv2-get query #140

Dart-net opened this issue Apr 12, 2021 · 0 comments

Comments

@Dart-net
Copy link

Dart-net commented Apr 12, 2021

Hey! I try to create simple snmp GET query using pyasn1-modules lib, with following code:
`
import sys
import socket

from pyasn1_modules.rfc1901 import Message
from pyasn1_modules.rfc1905 import PDUs, VarBindList, VarBind, GetRequestPDU
from pyasn1.type import univ
from pyasn1.codec.ber import decoder
from pyasn1.codec.ber import encoder
from pyasn1 import debug

// Define settings
community = 'test'
host = '1.2.3.4'
oid = '1.3.6.1.2.1.2.2.1.2.1'
// Create msg
msg = Message()
msg.setComponentByPosition(0)
msg.setComponentByPosition(1, community) // Set community
pdus = PDUs() # create pdus
pdus = msg.setComponentByPosition(2, pdus).getComponentByPosition(2)
pdu = pdus.setComponentByPosition(0).getComponentByPosition(0)
pdu.setComponentByPosition(0, 123)
pdu.setComponentByPosition(1, 0)
pdu.setComponentByPosition(2, 0)
vbl = pdu.setComponentByPosition(3).getComponentByPosition(3)
vb = vbl.setComponentByPosition(0).getComponentByPosition(0)
vb.setComponentByPosition(0, oid)
res = vb.getComponentByPosition(1).setComponentByPosition(1).getComponentByPosition(1)

print('sending: %s' % msg.prettyPrint())

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(encoder.encode(msg), (host, 161))

substrate, _ = sock.recvfrom(2048)
rMsg, _ = decoder.decode(substrate, asn1Spec=msg)

print('received: %s' % rMsg.prettyPrint())
`

After running script, got this exception: pyasn1.error.PyAsn1Error: Attempted "eq" operation on ASN.1 schema object. Can anybody help me, please ?
pyasn1.error.PyAsn1Error: Error encoding <Message schema object, tagSet=<TagSet object, tags 0:32:16>, subtypeSpec=, componentType=<NamedTypes object, types <NamedType object, type version=<Integer schema object, tagSet <TagSet object, tags 0:0:2>, namedValues <NamedValues object, enums version-2c=1>>>, <NamedType object, type community=<OctetString schema object, tagSet <TagSet object, tags 0:0:4>, encoding iso-8859-1>>, <NamedType object, type data=<Any schema object, encoding iso-8859-1>>>, sizeSpec=>: Error encoding <Integer schema object, tagSet <TagSet object, tags 0:0:2>, namedValues <NamedValues object, enums version-2c=1>>: Attempted "eq" operation on ASN.1 schema object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant