我曾经在我的Ubuntu上安装过nmap7.1,并在路径/usr/share/nmap/scripts中添加了一些nse脚本,但是当我删除nmap7.1并使用官方源代码安装nmap7.5并自行编译时,我发现有一些nse脚本是我曾经添加的,而nmap命令不能使用这些脚本,但是我的python程序需要这些nse脚本,所以我的问题是是这些nse脚本应该添加到哪里,或者哪个命令可以将这个nse脚本添加到Nmap路径并正常工作。谢谢!

最佳答案

我已经解决了我的问题:这是我的消费结构:

scan_s/nse/modicon-info.nse
      /namp.py

这是我的python脚本:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from libnmap.process import NmapProcess
from time import sleep
try:
  import xml.etree.cElementTree as ET
except ImportError:
  import xml.etree.ElementTree as ET
import sys

nmap_proc = NmapProcess(targets="45.76.197.202", options="--script nse/s7-info.nse -p 102")
nmap_proc.run_background()
while nmap_proc.is_running():
    sleep(2)
xml = nmap_proc.stdout
print xml
xmlfiled = open('testxml.xml','w')
xmlfiled.write(xml)
xmlfiled.close()
try:
    tree = ET.parse('testxml.xml')
    root =  tree.getroot()
    test = root.find('host').find('ports').find('port').find('script')
    test_dic = dict(test.attrib)
    s = test_dic['output']
except:
    s = 'unknown'
print s

希望它能帮助你:)

10-07 14:18