0
from scapy.all import *
pkts = rdpcap("lalalao.pcap")
for p in pkts:
## print p.time
if IP in p: #if packet has IP layer
src_ip = p[IP].src
dest_ip = p[IP].dst
print src_ip
f = open('IP_src.txt', 'a+')
for ip in src_ip:
f.writelines(ip)
f.close()
The above code correctly prints src_ip one per line:
216.58.202.229
216.58.202.229
192.168.1.3
216.58.202.229
216.58.202.229
192.168.1.3
216.58.202.229
216.58.202.229
192.168.1.3
216.58.202.229
192.168.1.3
216.58.202.229
But when saving to Ip_src.txt file, the file gets all messy , all on the same line. How to save src_ip in the file one per line? When I pass this file to another program read, is it any problem for src_ip to be one per line? There is a difference between python 2 and python 3 at this point?
f. write('{} n'.format(ip)), try this Ed
– Miguel