简体   繁体   中英

print scapy sniff output to file

I have created a sniffer in scapy and I want the packets captured by scapy to be written onto a file for further analysis?

def sniffer(ip):
    filter_str = "icmp and host " + ip
    packets=sniff(filter=filter_str,count=20)
    f = open('log.txt',"a")
    #f.write(packets)

The last line of code does not work. Is there any way I could do this?

f.write expects a character buffer, but you supply it with a Sniffed object which is the result of calling sniff . You can, very simply, do the following:

f.write(str(packets))

This should work. But it probably won't display the information exactly as you would like it. You are going to have to do more work collecting information from packets as strings before you write to f .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM