spot
spot

Reputation: 27

how to use nse in python

how to use nse in python? for example

nmap -p80 google.com --script=http-enum
Output: 
PORT   STATE SERVICE
80/tcp open  http
| http-enum: 
|_  /partners/: Potentially interesting folder
 

Python:

nm.scan('google.com', arguments=f'-p80 --script=http-enum')
Output:
{'142.250.186.142': {'nmap': {'command_line': 'nmap -oX - -p80 --script=http-enum 142.250.186.142', 'scaninfo': {'tcp': {'method': 'connect', 'services': '80'}}, 'scanstats': {'timestr': 'Tue Jul 12 07:38:13 2022', 'elapsed': '11.03', 'uphosts': '1', 'downhosts': '0', 'totalhosts': '1'}}, 'scan': {'142.250.186.142': {'hostnames': [{'name': 'fra24s07-in-f14.1e100.net', 'type': 'PTR'}], 'addresses': {'ipv4': '142.250.186.142'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'syn-ack'}, 'tcp': {80: {'state': 'open', 'reason': 'syn-ack', 'name': 'http', 'product': '', 'version': '', 'extrainfo': '', 'conf': '3', 'cpe': ''}}}}}}

Upvotes: 0

Views: 153

Answers (1)

viggnah
viggnah

Reputation: 1879

When called in python, looks like it returns a dictionary with all the info. To get specific info you can access these attributes separately as shown in the docs. If instead, you want to run the same command on the command line from a python script you can use subprocess:

import subprocess
command = "nmap -p80 google.com --script=http-enum"
subprocess.Popen(command.split(' '))

Upvotes: 1

Related Questions