运行以下脚本时,没有打印任何内容,但当我按ctrl+c并结束任务时,打印完整的输出。我想使它在一种方式,每一行的列表是动态打印的,因为脚本本身正在运行我要运行的函数是…'
`def passive_scan(interface):
result=[]
ip=[]
packets = []
mode="p"
sniff(iface="eth0", prn=filter_packets(packets),timeout= 10000)
for p in packets:
if p[0]["ARP"].op==2:
src_mac=p[0]["ARP"].hwsrc
src_ip=p[0]["ARP"].psrc
ip.append(src_ip)
dict={"mac":src_mac,"ip":src_ip}
result.append(dict)
for client in result:
client["count"]=countOf(ip,client["ip"])
print_result(result,mode)`
'我使用的输出打印函数是.....
```
`print("Interface: "+interface+"ttMode: PassivetttFound "+str(len(list))+" hosts")
print("----------------------------------------------------------------------------")
print("MACttttIPtttHost Activity")
print("----------------------------------------------------------------------------")
for client in list:
print(client["mac"] + "tt" + client["ip"]+"tt"+str(client["count"]))`
```
```
`
i was able to properly format the output but to get that to print i have to end the task than only it prints
the required output should look like..
[enter image description here](https://i.stack.imgur.com/4g14d.png)
这是sniff()
的预期行为,它是一个阻塞函数。
"sniff()
函数监听无限时间,直到用户中断。">
你应该使用AsyncSniffer
: https://scapy.readthedocs.io/en/latest/usage.html#asynchronous-sniffing