防止scapy打印结果

时间:2016-02-17 21:48:43

标签: python snmp scapy

所以我在Scapy中有一个SNMP脚本,如下所示:

for i in range(j, k+1):
    ip = iprange + str(i)
    print 'Sending SNMP request to: ' +ip + "\n"
    p = IP(dst=ip)
    SNMP(community="public", PDU=SNMPget(id=1416992799, varbindlist=[SNMPvarbind(oid=ASN1_OID("1.3.6.1.2.1.1.1.0"))]))
    pkt = sr1(p, timeout=0.08)

当我受到打击(答案为1)时,我得到了理想的结果:

Sending SNMP request to: 192.168.1.200

Begin emission:
.Finished to send 1 packets.

Received 1 packets, got 0 answers, remaining 1 packets
Sending SNMP request to: 192.168.1.201

Begin emission:
.Finished to send 1 packets.

Received 1 packets, got 1 answers, remaining 1 packets

然而,我只是希望Scapy在答案为1时打印出结果,而不是在我没有命中(0)时打印出结果。是否可以在Scapy中执行此操作?

1 个答案:

答案 0 :(得分:0)

scapy / sendrecv.py中的第205行读取

if verbose:
    print "\nReceived %i packets, got %i answers, remaining %i packets" % (nbrecv+len(ans), len(ans), notans)

所以没有选项只能在ans>时打印出来。 0(请注意,在该功能的上下文中无法快捷打印此打印件)。您可以将源代码更改为

if verbose and len(ans)>0:
    print "\nReceived %i packets, got %i answers, remaining %i packets" % (nbrecv+len(ans), len(ans), notans)

或更优选,只需更好地解析输出。

相关问题