문제

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