IPv6链路本地地址作为PySNMP中的UDP6TransportTarget?

时间:2016-02-21 17:10:02

标签: python-3.x ipv6 pysnmp link-local

我正在尝试在链接本地地址FE80::1:1%enp0s8上向代理进行SNMP查询。这是代码:

#!/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))

其中enp0s8是我找到代理的界面。但是,当我使用它时,我收到此错误消息:

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

当我没有为此链接本地地址指定接口时,我会抽出时间。使用snmpget实用程序指定范围有效。

我的问题是:如何使用Udp6TransportTarget

指定IPv6链接本地地址的范围

0 个答案:

没有答案