gee*_*oph 0 python sniffing scapy
如何计算使用该数据包捕获的数据包数量
packets = sniff(filter='udp and host fe80::xx:xx:xx:xx',count=0)
Run Code Online (Sandbox Code Playgroud)
功能?这可能吗?
编辑:
我实际上一直在尝试使用这个函数的prn:
def packetCount(packets):
global counter
counter += 1
Run Code Online (Sandbox Code Playgroud)
我在程序开头定义了计数器变量.但我需要将它重置为0,每次嗅探().我尝试过的任何东西都无法工作......
sniff 需要使用几个参数.
>>> print sniff.__doc__
Sniff packets
sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] + L2ListenSocket args) -> list of packets
count: number of packets to capture. 0 means infinity
store: wether to store sniffed packets or discard them
prn: function to apply to each packet. If something is returned,
it is displayed. Ex:
ex: prn = lambda x: x.summary()
lfilter: python function applied to each packet to determine
if further action may be done
ex: lfilter = lambda x: x.haslayer(Padding)
offline: pcap file to read packets from, instead of sniffing them
timeout: stop sniffing after a given time (default: None)
L2socket: use the provided L2socket
opened_socket: provide an object ready to use .recv() on
stop_filter: python function applied to each packet to determine
if we have to stop the capture after this packet
ex: stop_filter = lambda x: x.haslayer(TCP)
Run Code Online (Sandbox Code Playgroud)
你可能会发现timeout或count有用.
编辑:找到嗅探的数据包数量,可以使用该len()功能:
len(packets)
for i in range(len(packets)):
print packets[i].summary()
# or better:
for i in packets:
print i.summary()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5997 次 |
| 最近记录: |