Skip to content

Commit aa4ef57

Browse files
committed
fix a bug in snmpwalk()
1 parent c2acc60 commit aa4ef57

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

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
@@ -10086,3 +10086,15 @@ assert raw(created) == b'\x80\x11\x124\x00\xbcaN\xab\xcd\xef\x01'
1008610086
parsed = RTP(raw(created))
1008710087
assert parsed.sourcesync == 0xabcdef01
1008810088
assert "RTPExtension" not in parsed
10089+
10090+
= Test snmpwalk()
10091+
10092+
~ netaccess
10093+
def test_snmpwalk(dst):
10094+
with ContextManagerCaptureOutput() as cmco:
10095+
snmpwalk(dst=dst)
10096+
output = cmco.get_output()
10097+
expected = "No answers\n"
10098+
assert(output == expected)
10099+
10100+
test_snmpwalk("secdev.org")

0 commit comments

Comments
 (0)