0

All,

Is there an easy way to access/utilize the nse packages from python?

Thanks

user492554
  • 21
  • 1
  • 5

3 Answers3

2

You can use python-nmap package for that,

Here is an example:

>>> import nmap
>>> nm=nmap.PortScanner()
>>> nm.scan('192.168.1.212', '445', 
         arguments='--script=/usr/local/share/nmap/scripts/smb-os-discovery.nse')

Output:

{'nmap': {'command_line': u'nmap -oX - -p 445 --script=/usr/local/share/nmap/scripts/smb-os-discovery.nse 192.168.1.212',
  'scaninfo': {u'tcp': {'method': u'syn', 'services': u'445'}},
  'scanstats': {'downhosts': u'0',
   'elapsed': u'0.28',
   'timestr': u'Fri Aug 31 21:33:19 2012',
   'totalhosts': u'1',
   'uphosts': u'1'}},
 'scan': {u'192.168.1.212': {'hostname': u'BookLife',
   'script': {u'smb-os-discovery': u'\n  OS: Unix (Samba 3.2.5)\n  Computer name: localhost\n Domain name: localdomain\n  FQDN: localhost.localdomain\n  NetBIOS computer name: \n  System time: 2012-07-19 09:27:12 UTC+7\n'},
   'status': {'reason': u'arp-response', 'state': u'up'},
   u'tcp': {445: {'name': u'microsoft-ds',
     'product': None,
     'reason': u'syn-ack',
     'state': u'open',
     'version': None}}}}}
Omid Raha
  • 9,862
  • 1
  • 60
  • 64
1

Yeah i would suggest calling subprocess and calling nmap that way.

example

import subprocess

subprocess.call('nmap', '-sS', '127.0.0.1')
iNoob
  • 1,375
  • 3
  • 19
  • 47
0

While there are some libraries for integrating Lua into Python programs, the Nmap Scripting Engine (NSE) is tightly integrated into the Nmap scanner itself, and can't really be separated. As Pol mentioned, running Nmap as an external command is entirely possible, and the script results could be parsed from the output.

bonsaiviking
  • 5,825
  • 1
  • 20
  • 35
  • could you please check this https://stackoverflow.com/questions/61098484/nmap-engine-failed-to-load-a-script , I'm having an issue when i load some NSE scripts –  Apr 08 '20 at 11:03