Search code examples
pythonnmap

Python script - launch nmap with parameters


The scripts launches the application nmap. Only it doesn't print out the var to the application nmap. It does however if I print them separately.

Looking for some suggestions, many thanks.

Image script - Image output

Script:

import os
import subprocess

xIP=input("Please enter IP-address to use on NMAP port-scan: ")
xOP=input("Please apply options to add on port-scan: ")

print("Entered values: ", xIP + xOP)

command = "nmap print xIP xOP"
#os.system(command)
subprocess.Popen(command)

input("Press ENTER to exit application...")

Solution

  • See here: https://docs.python.org/3/library/subprocess.html#subprocess.Popen

    Split the program name and the arguments, the first item in the list it expects is the name of the program to run.

    In your case, subprocess.Popen(command.split(' ')) may suffice.