I'm retrieving a hex-string format IP address of CDP neighboor from the router using NET-SNMP. However, I get instead something weird thing. Any help? Thank you

有帮助吗?

解决方案

As alecxe mentioned, you really need to provide more details when asking questions. Fortunately, I've used the NET-SNMP bindings for Python and already know what you are talking about.

To convert the binary data you receive from the NET-SNMP bindings to a hex representation, use the Python binascii module. The b2a_hex function is what you are looking for.

The following is mostly from memory, so it may not be exactly correct, but probably close enough to give you an idea.

import netsnmp
import binascii

session = netsnmp.Session(Community='public', DestHost='myagentip', Version=1)
vbwithbinarydata = netsnmp.VarBind('oid_to_binary_data')
varlist = netsnmp.Varlist(vbwithbinarydata)
session.get(varlist)
print binascii.b2a_hex(vbwithbinarydata.val)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top