Is there any way I can use 'nmap' port scanner, to generate and output result on my Django App
Question
I'm trying to create some network app in Django, and what I would like to ask: Is it possible to do something like this: Client type IP address, than server scans it with 'nmap', after that the result passed to the Django app, and than I do whole bunch of stuff with it.
Just want to know is it possible to make it, or it sounds ridiculous?
La solution
My suggestion would be something along the lines of:
pout,perr = subprocess.Popen(['nmap', '192.168.1.2', '-oX', '-'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
xml_results = pout.read()
There are a couple nmapXML -> Python dict scripts floating around as well if you google a bit.
There's somewhat of a problem with this approach - lets call it the naive approach because it doesn't scale very well, or deal with things like the machine not pinging and nmap falling back to slow-scan (which can take literally hours depending on the target network)
Consider making a server that runs nmap asyncronously and can provide status back to the user - as well as the ability to cancel a scan in progress.
Autres conseils
Nmap has a python library (or a wrapper?) called python-nmap at https://pypi.python.org/pypi/python-nmap.
You can install it using
pip install python-nmap
You can use a library like celery
to use it in Django