Skip to content

Commit bef68d1

Browse files
authored
Merge pull request #1238 from karpierz/fix_a_bug_in_snmpwalk
Scapy 2.4.0: fix a bug in 'snmpwalk()'
2 parents 2c9361b + aa4ef57 commit bef68d1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

scapy/layers/snmp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ def snmpwalk(dst, oid="1", community="public"):
248248
try:
249249
while True:
250250
r = sr1(IP(dst=dst)/UDP(sport=RandShort())/SNMP(community=community, PDU=SNMPnext(varbindlist=[SNMPvarbind(oid=oid)])),timeout=2, chainCC=1, verbose=0, retry=2)
251-
if ICMP in r:
252-
print(repr(r))
253-
break
254251
if r is None:
255252
print("No answers")
256253
break
254+
if ICMP in r:
255+
print(repr(r))
256+
break
257257
print("%-40s: %r" % (r[SNMPvarbind].oid.val,r[SNMPvarbind].value))
258258
oid = r[SNMPvarbind].oid
259259

test/regression.uts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10098,3 +10098,15 @@ assert raw(created) == b'\x80\x11\x124\x00\xbcaN\xab\xcd\xef\x01'
1009810098
parsed = RTP(raw(created))
1009910099
assert parsed.sourcesync == 0xabcdef01
1010010100
assert "RTPExtension" not in parsed
10101+
10102+
= Test snmpwalk()
10103+
10104+
~ netaccess
10105+
def test_snmpwalk(dst):
10106+
with ContextManagerCaptureOutput() as cmco:
10107+
snmpwalk(dst=dst)
10108+
output = cmco.get_output()
10109+
expected = "No answers\n"
10110+
assert(output == expected)
10111+
10112+
test_snmpwalk("secdev.org")

0 commit comments

Comments
 (0)