I've tried everything on this page and a few other Google searches, but I can't seem to get this to work.
Note* I looked up help on printing to test out the output from outfile.write
, but I still can't get it formatted properly in testing.
My code looks like:
def ipfile():
global ip_targets
ip_target_file = raw_input('Place target file location here: ')
try: ip_holder = open(ip_target_file,'r')
except IOError:
os.system('clear')
print('Either I can\'t read that file, or it\'s not a file')
os.system('sleep 3')
return
ip_targets = ip_holder.readlines()
def inbound_connections():
i = 0
uri_ip_src = ''
uri_ip_dst = ''
while i < (len(ip_targets)):
uri_ip_src_repeater = ('ip.src%3D%3D' + ip_targets[i])
uri_ip_src = uri_ip_src + '||' + uri_ip_src_repeater
uri_ip_dst_repeater = ('ip.dst%3D%3D' + ip_targets[i])
uri_ip_dst = uri_ip_dst + '||' + uri_ip_dst_repeater
i += 1
url = '&expression=' + "(" + (uri_ip_src[2:]) + ")" + "%26(" + (uri_ip_dst[2:]) + ")"
#Write output to file functions
outfile=open("jacobi_queries.txt","a")
outfile.write("Same -> Same Connections " + str(datetime.datetime.now())[:16])
outfile.write("\n")
outfile.write(call_moloch + "/sessions?" + timestamp + url + "' 2>/dev/null &")
outfile.write("\n")
outfile.close()
The code works (sorry I'm leaving some variables out that are from other functions, but assume they work) however, my output has line breaks and I can't seem to find where I need to transform the "uri_ip_src" and "uri_ip_dst" to make it output on one line. My output looks as such:
Same -> Same Connections 2018-06-05 05:30
nohup firefox 'localhost:8005/sessions?&date=6&expression=(ip.src%3D%3D10.0.2.15
||ip.src%3D%3D10.0.0.1
||ip.src%3D%3D127.0.0.1
)%26(ip.dst%3D%3D10.0.2.15
||ip.dst%3D%3D10.0.0.1
||ip.dst%3D%3D127.0.0.1
)' 2>/dev/null &