I am trying to make SNMP query to agent on link-local address FE80::1:1%enp0s8
. Here is the code:
#!/usr/bin/python3
from pysnmp.hlapi import *
USER_KEY='manager1'
AUTH_PROT=usmHMACMD5AuthProtocol
PRIV_PROT=usmAesCfb256Protocol
userData = UsmUserData('manager', authKey=USER_KEY,
privKey=USER_KEY,
authProtocol=AUTH_PROT,
privProtocol=PRIV_PROT)
target=Udp6TransportTarget(('FE80::1:1%enp0s8',161))
g = getCmd(SnmpEngine(),
userData,
target,
ContextData(),
ObjectType(ObjectIdentity('SNMPv2-MIB','sysUpTime',0)))
print(next(g))
where enp0s8
is my interface where I would find the agent. However, when I use this I get this error message:
Traceback (most recent call last):
File "get-SNMP-var.py", line 21, in <module>
print(next(g))
File "/usr/lib/python3.5/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 107, in getCmd
lookupMib=options.get('lookupMib', True)))
File "/usr/lib/python3.5/site-packages/pysnmp/hlapi/asyncore/cmdgen.py", line 122, in getCmd
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
File "/usr/lib/python3.5/site-packages/pysnmp/hlapi/lcd.py", line 107, in configure
transportTarget.tagList
File "/usr/lib/python3.5/site-packages/pysnmp/entity/config.py", line 269, in addTargetAddr
transportAddress = TransportAddressIPv6(transportAddress)
File "/usr/lib/python3.5/site-packages/pyasn1/type/univ.py", line 312, in __init__
base.AbstractSimpleAsn1Item.__init__(self, value, tagSet, subtypeSpec)
File "/usr/lib/python3.5/site-packages/pyasn1/type/base.py", line 74, in __init__
value = self.prettyIn(value)
File "<string>", line 217, in prettyIn
OSError: illegal IP address string passed to inet_pton
When I don't specify the interface for this link-local address I get time out. Using snmpget
utility with specifying scope works.
My question is: How can I specify scope of IPv6 link-local address using Udp6TransportTarget
?