safe_mode 设置为 True (libnmap) 时激活不安全选项

unsafe options activated while safe_mode is set True (libnmap)

我正在尝试 nmap IP 和主机名,但我一直收到错误消息,"unsafe options activated while safe_mode is set True"。我试过放置 safe_mode=False 和 safe_mode=True,以及在 nmap 扫描中没有选项。这是我的代码:

from libnmap.parser import NmapParser
from libnmap.process import NmapProcess

def menu():
    print "Enter 1 for IP input, 2 for Hostname input"
    return input ("Number: ")

#Begin NMAP scan
def nmaprun():
    print ip
    nm = NmapProcess(ip, options="-sV -oX test.xml safe_mode=False")
    rc = nm.run()

def nmapparse():
    print "Nmap Information: "
    rep = NmapParser.parse_fromfile('test.xml')

#Parses the NMAP Information in a readable format
    for _host in rep.hosts:
            if _host.is_up():
                print("Host: {0} {1}".format(_host.address,
                                       " "      .join(_host.hostnames)))

        # get CPE from service if available
            for s in _host.services:
                    print("    Service: {0}/{1} ({2}) ({3}) {4}".format(s.port,
                                                                s.protocol,
                                                                s.state,
                                        s.service,
                                        s.banner))
            # NmapService.cpelist returns an array of CPE objects
                    for _serv_cpe in s.cpelist:
                        print("        CPE: {0}".format(_serv_cpe.cpestring))



            if _host.os_fingerprinted:
                    print("  OS Fingerprints")
                    for osm in _host.os.osmatches:
                        print("    Found Match:{0} ({1}%)".format(osm.name,
                                                          osm.accuracy))
                # NmapOSMatch.get_cpe() method return an array of string
                # unlike NmapOSClass.cpelist which returns an array of CPE obj
                        for cpe in osm.get_cpe():
                                print("\t    CPE: {0}".format(cpe))

loop = 1
while loop == 1:
    choice = menu()
    if choice == 1:
        ip = raw_input("Enter your IP: \n")
        loop = 0
    elif choice == 2:
        hostname = raw_input("Enter your hostname: \n")
        loop = 0
    elif choice > 2 or choice < 1:
        print "No options selected"
        loop = 0

nmaprun()
nmapparse()

safe_modeNmapProcess 的参数,不是选项:

nm = NmapProcess(ip, options="-sV -oX test.xml", safe_mode=False)

我通过查看source code找到了答案:

class NmapProcess(Thread):
    def __init__(self, targets="127.0.0.1",
                 options="-sT", event_callback=None, safe_mode=True, fqp=None):