开发者

Invoking nmap (nse) from python

开发者 https://www.devze.com 2023-01-27 08:46 出处:网络
All, Is there an easy way to access/utilize the n开发者_C百科se packages from python? ThanksYou can use python-nmap package for that,

All,

Is there an easy way to access/utilize the n开发者_C百科se packages from python?

Thanks


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}}}}}


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

example

import subprocess

subprocess.call('nmap', '-sS', '127.0.0.1')


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消