The “send’n’receive” functions family is the heart of Scapy. They return a couple of two lists. The first element is a list of couples (packet sent, answer), and the second element is the list of unanswered packets. These two elements are lists, but they are wrapped by an object to present them better, and to provide them with some methods that do most frequently needed actions:
1 2 3 4 5 6 7 8
>>> sr(IP(dst="192.168.8.1")/TCP(dport=[21,22,23])) Received 6 packets, got 3 answers, remaining 0 packets (<Results: UDP:0 TCP:3 ICMP:0 Other:0>, <Unanswered: UDP:0 TCP:0 ICMP:0 Other:0>) >>> ans,unans=_ >>> ans.summary() IP / TCP 192.168.8.14:20 > 192.168.8.1:21 S ==> Ether / IP / TCP 192.168.8.1:21 > 192.168.8.14:20 RA / Padding IP / TCP 192.168.8.14:20 > 192.168.8.1:22 S ==> Ether / IP / TCP 192.168.8.1:22 > 192.168.8.14:20 RA / Padding IP / TCP 192.168.8.14:20 > 192.168.8.1:23 S ==> Ether / IP / TCP 192.168.8.1:23 > 192.168.8.14:20 RA / Padding
list:sr() //tuple [0]:<answer> // scapy.plist.SndRcvList [1]:<unanswer> // scapy.plist.PacketList list:<answer> // scapy.plist.SndRcvList [0]:a couple of two list // scapy.plist.QueryAnswer [1]:a couple of two list [2]:a couple of two list ... [n] :a couple of two list list:<answer>[index] // scapy.plist.QueryAnswer [0]:pkt sent //pkt [1]:pkt receive //pkt
summary(prn=None, lfilter=None) method of scapy.plist.SndRcvList instance prints a summary of each packet
:param prn: function to apply to each packet instead of lambda x:x.summary() :param lfilter: truth function to apply to each packet to decide whether it will be displayed (END)
这是示例代码:
1 2 3 4 5
ans.summary( lambda s,r: r.sprintf("%TCP.sport% \t %TCP.flags%") ) 440 RA 441 RA 442 RA https SA