I want to save result of script to file. Example of script:
import os
def scan_ip():
ip2 = raw_input('Enter ip of target: ')
target = 'nmap -sP {}'.format(ip2)
os.system(target + > '123.txt')
I want to save result of script to file. Example of script:
import os
def scan_ip():
ip2 = raw_input('Enter ip of target: ')
target = 'nmap -sP {}'.format(ip2)
os.system(target + > '123.txt')
You should not do in this way. First you need to call the external command with output captured, and then write the output you captured to a file:
import subprocess
ip2 = raw_input('Enter ip of target: ')
p = subprocess.Popen(["nmap", "-sP", ip2], stdout=subprocess.PIPE)
out, err = p.communicate()
with open('123.txt', 'w') as f:
f.write(out)