0

I want to use a python script to use nmap. I realize there is a package for python-nmap. But I want to create a simple script that interprets the output of nmap command then does some more things depending on it's output.

Attempting to use check_output("nmap") like this link does:

Running shell command from Python and capturing the output

by running this :

sp.check_output(
"nmap",
stderr=sp.STDOUT)

I get the error:

CalledProcessError: Command 'nmap' returned non-zero exit status 255

The command works with apt-get, ls and python. I think it is probably that nmap is an installed program and check_output is searching in the right place to find it.

nmap works in my terminal.

Any pointers?

Community
  • 1
  • 1
wgwz
  • 2,642
  • 2
  • 23
  • 35

1 Answers1

0

OK, got it. You have to pass some arguments to nmap for successfully execution, as well 'shell' should be enabled. Following command works:

subprocess.check_output("nmap -V", shell=True)
Samuel
  • 3,631
  • 5
  • 37
  • 71