Python Forum
Specific Issue with pysnmp
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Specific Issue with pysnmp
#1
I am just getting started with Python and was hoping to use it to query routers and switches for information like device names, serial numbers etc. My knowledge of Python is from looking at other people's scripts so the syntax might not be perfect.
I am using pysnmp. I pass the IP address and SNMP string as command line parameters and I know that part of the script is working fine . I confirmed by also replacing these variables with hardcoded values in the script. The error that I get stays consistent.
What could I be doing wrong? Please let me know if this post goes to some other group on this forum.
My code is
import pysnmp
import sys
import os

from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher
from pysnmp.carrier.asyncore.dgram import udp, udp6, unix
from pysnmp.entity.rfc3413.oneliner import cmdgen
from pyasn1.codec.ber import encoder, decoder
from pysnmp.proto import api


if __name__ == '__main__':
    ip_addr  = sys.argv[1]
    community_string = sys.argv[2]
    SNMP_PORT = 161
    cg = cmdgen.CommandGenerator()
    comm_data=cmdgen.CommunityData(community_string)
    v_transport = cmdgen.UdpTransportTarget(ip_addr,SNMP_PORT)
#    v_transport = cmdgen.UdpTransportTarget('192.168.1.1,SNMP_PORT)
    v_oid = (1,3,6,1,4,1,9,3,6,3,0)
    result =  cg.getCmd(comm_data,v_transport,v_oid)
    print result
The error that I get is
File "snmpq.py", line 18, in <module>
v_transport = cmdgen.UdpTransportTarget(ip_addr,SNMP_PORT)
File "C:\Python27\lib\site-packages\pysnmp\hlapi\transport.py", line 19, in __
init__
self.transportAddr = self._resolveAddr(transportAddr)
File "C:\Python27\lib\site-packages\pysnmp\hlapi\asyncore\transport.py", line
63, in _resolveAddr
'@'.join([str(x) for x in transportAddr]), sys.exc_info()[1]))
pysnmp.error.PySnmpError: Bad IPv4/UDP transport address 1@9@2@.@1@6@8@.@1@.@1
: [Errno 11004] getaddrinfo failed


I am trying to reach 192.168.1.1 and can successfully query SNMP using snmpwalk or snmpget
Reply
#2
good share thank you
g club
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pysnmp how to find msgGlobalData msgID from snmpV3 inform charliebsimms 0 1,919 Mar-05-2021, 11:13 AM
Last Post: charliebsimms

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020