I am using the sniff() function of Scapy to sniff packet from the ethernet. I store it in a variable called pkt. Later I want to make a copy of the same by appending contents of pkt in another variable buffpkt. Initially I declared both the variables as list but once pkt store the sniff() output it changes its type to instance. Below is the code.

pkt=[]
buffpkt=[]
pkt=sniff(prn=lambda x:x.sprintf("{IP : %IP.src%  %IP.dst%\n\n} "),timeout=5,store=1)
buffpkt=pkt

I want to make a big list of all the packets sniffed by appending the results to buffpkt but I cannot. Any suggestions?

有帮助吗?

解决方案

By just assigning one list to another, you just make the first list point to the second list. To copy the list you can use the slicing operator, like this:

buffpkt = pkt[:]

Now buffpkt will be a copy.

其他提示

Use standard library copy to copy data structures in Python: http://docs.python.org/library/copy.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top