Issue
how would I be able to make a new line after each string has been found in Python? Any help would be greatly appreciated, other search methods (GREP, SED) are welcome. Anything that will search through the output, take key words and output each result on a new line. Thanks.
At the moment the output is:
['+ Target IP: 127.0.0.1', '+ Target Hostname: 127.0.0.1', '+ Server: Apache/2.4.46 (Debian)']
I'd like the output to look like:
Target IP: 127.0.0.1
Target Hostname: 127.0.0.1
Server: Apache/2.4.46 (Debian)
Python Code:
#!/usr/bin/python
import subprocess
import os
def bash(command):
return subprocess.check_output(['bash', '-c', command])
def niktoScan():
res = bash("nikto -h %s | awk '/Target IP|Hostname|Server/ ' " % niktoValue).splitlines()
print(res)
niktoScan()
Solution
if all the elements in the list are all ways prefixed with '+ ' you could just
get rid of the first two chars by slicing all the indiviudual strings starting from the second index and use '\n'.join()
(the string the join method is called on is the delimeter used to seperate the eliments) to join them back together and print them.
print('\n'.join([i[2:] for i in res]))
Answered By - poison_pwn Answer Checked By - Timothy Miller (WPSolving Admin)