[英]i am un able to get the script to print the output dynamicaly
運行以下腳本時,不會打印任何內容,但當我按 ctrl+c 並結束任務時,會打印完整的 output。 我想以一種方式使列表的每一行都動態打印,因為腳本本身正在運行我正在嘗試運行的 function 是...`
`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)`
` 我正在使用的 output 打印 function 是......
```
`print("Interface: "+interface+"\t\tMode: Passive\t\t\tFound "+str(len(list))+" hosts")
print("----------------------------------------------------------------------------")
print("MAC\t\t\t\tIP\t\t\tHost Activity")
print("----------------------------------------------------------------------------")
for client in list:
print(client["mac"] + "\t\t" + client["ip"]+"\t\t"+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()
的預期行為,它是一個阻塞 function。
“ sniff()
function 會無限期地監聽,直到用戶中斷。”
您應該使用AsyncSniffer
: https://scapy.readthedocs.io/en/latest/usage.html#asynchronous-sniffing
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.