From 988fe062a2f7526327e4e6304c9cecdbb048c0e5 Mon Sep 17 00:00:00 2001 From: Kevin Read Date: Thu, 9 Jul 2020 16:16:45 +0200 Subject: [PATCH] Add support to walk grammar for reading HEX-STRING from an unknown windows version of snmpwalk. --- snmpsim/grammar/walk.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/snmpsim/grammar/walk.py b/snmpsim/grammar/walk.py index ed2f847..c09d4b3 100644 --- a/snmpsim/grammar/walk.py +++ b/snmpsim/grammar/walk.py @@ -97,8 +97,12 @@ def _hex_string_filter(value): match = re.match(r'^([0-9a-fA-F]{2}(\s+[0-9a-fA-F]{2})*)\s+\[', value) if match: return [int(y, 16) for y in match.group(1).split(' ')] - - return [int(y, 16) for y in value.split(' ')] + elif ' ' in value: + return [int(y, 16) for y in value.split(' ')] + else: + # This could be the format returned by some unknown windows snmpwalk tool: + # .1.3.6.1.2.1.2.2.1.6.1 = HEX-STRING: 00029929AE3C + return [int(value[i:i+2], 16) for i in range(0, len(value), 2)] @staticmethod def _gauge_filter(value):