So I am running code that looks like this on Ubuntu 11.4 and Python 2.7:
p_scan_command = "sudo nmap -sC -sV -PN -O 192.168.0.1/24"
time.sleep(1.5)
os.system(p_scan_command)
f = open('nmapscan1.log', 'r')
print f.read()
f.close()
What is happening is that I end up with no results, and the scan is not being run, probably because it is being run with ‘sudo’. I want to know
- If I have been correct in my diagnosis of the problem and
- How to fix it?
Are you sure that the log file is even created? I cannot see where this name is mentionned – but maybe it is created by default.
Are you asked for the password by
sudo?This could tell you if sudo is really run.
os.systemis kind of deprecated or at least frowned upon; better usesubprocess.call(),subprocess.check_call()orsubprocess.Popen()(gives you an object which you can use to further control the process).EDIT: Just tested. Here the scan runs, but the output gets displayed instead of written to a file. Probably you are missing the
> nmapscan1.logpart in theos.system()call.With
subprocess, you would writeor if you don’t need the file, simply