gescheit / fastsnmp

Fast SNMP poller
MIT License
19 stars 7 forks source link

Inconsistent type returned #4

Closed bajojoba closed 6 years ago

bajojoba commented 7 years ago

Hi,

First of all great job 👍

I'm trying to poll OID: .1.3.6.1.2.1.10.127.1.3.3.1.3 (MIB: docsIfCmtsCmStatusIpAddress). The result should return an IP address format. When using your basic script in expamples directory I get the result value returned sometimes a string sometimes byte: host=0.0.0.0 oid=cmIP.21 value='b'0ae4e73e'' host=0.0.0.0 oid=cmIP.23 value='b'0ae28fc8'' host=0.0.0.0 oid=cmIP.32 value='b'0ae28150'' host=0.0.0.0 oid=cmIP.33 value='b'0ae4e6b0'' host=0.0.0.0 oid=cmIP.35 value=' ₆'

Bytes can be normaly decoded into an IP address while string is imposible to decode into an IP address. I've tried: if type(d[3]) is str: a = d[3] if len(a) == 3: b = ''.join(a).encode('utf-8') else: b = [ord(x) for x in a] ip = '{}.{}.{}.{}'.format(*b)

But the length of the string returned is just too small :(

Do you have any idea on how to solve this issue?

Thanks in advance and BR, Janko

gescheit commented 7 years ago

Hi! Try next code: socket.inet_ntop(socket.AF_INET, bytes.fromhex(b"0ae4e73e".decode())) I will be fixing this problem later.

bajojoba commented 6 years ago

Hi,

Your suggestion solved the problem. Thanks.