当前位置: 首页>>代码示例>>Python>>正文


Python NmapParser.parse方法代码示例

本文整理汇总了Python中libnmap.parser.NmapParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Python NmapParser.parse方法的具体用法?Python NmapParser.parse怎么用?Python NmapParser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在libnmap.parser.NmapParser的用法示例。


在下文中一共展示了NmapParser.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: nmap_scan

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def nmap_scan(hosts, output_dir):
    """
    if user chooses to start from an nmap scan, run the scan and then return an nmap_report object
    :param hosts:
    :param output_dir:
    :return:
    """
    print("[+] Kicking off nmap scan. I don't have  any feedback working, so just be patient")
    nm = NmapProcess(hosts, options="-sC -sV -Pn -p1-65535")
    rc = nm.run()
    nmap_report = NmapParser.parse(nm.stdout)
    nmap_xml = output_dir + "/" + hosts.replace("/","_") + "_nmap.xml"
    f = open(nmap_xml, 'a')
    f.write(nm.stdout)
    f.close()
    print("[+] Nmap scan saved to: {0}".format(nmap_xml))
    return nmap_report 
开发者ID:sethsec,项目名称:celerystalk,代码行数:19,代码来源:utils.py

示例2: nmap_parse_ports_by_host

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def nmap_parse_ports_by_host(scan_output):
    '''Accepts nmap scan output XML and returns a dict of hosts and tuples of corresponding
        open ports; only live hosts and open ports should be returned.
    
        e.g. {'192.168.0.171': [(80, 'tcp'), (111, 'tcp')]}
    
    '''
    try:
        hosts={}
        parsed = NmapParser.parse(scan_output)
        
        for host in parsed.hosts:
            if host.is_up():
                hosts[host.address] =  host.get_open_ports()
        
        return hosts
    except:
        print "\n[!] Error parsing scan output" 
开发者ID:isaudits,项目名称:autoenum,代码行数:20,代码来源:nmap.py

示例3: nmap_parse_hosts_by_port

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def nmap_parse_hosts_by_port(scan_output):
    '''Accepts nmap scan output XML and returns a dict of open ports and lists of the corresponding
        hosts with these ports open; only live hosts and open ports should be returned.
        
        e.g. {(80, 'tcp'): ['192.168.0.171'], (111, 'tcp'): ['192.168.0.169', '192.168.0.171']} 
    '''
    try:
        parsed = NmapParser.parse(scan_output)
        
        hosts={}    #e.g. {'192.168.0.171': [(80, 'tcp'), (111, 'tcp')]}
        ports={}    #e.g. {(80, 'tcp'): ['192.168.0.171'], (111, 'tcp'): ['192.168.0.169', '192.168.0.171']}
        
        for host in parsed.hosts:
            if host.is_up():
                host_ports =  host.get_open_ports()
                hosts[host.address] = host_ports
                for port in host_ports:
                    ports.setdefault(port,[]).append(host.address)
        
        return ports
    except:
        print "\n[!] Error parsing scan output" 
开发者ID:isaudits,项目名称:autoenum,代码行数:24,代码来源:nmap.py

示例4: nmap_parse_webhosts

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def nmap_parse_webhosts(scan_output):
    '''Accepts nmap scan output XML and returns text output suitable for passing to Nikto
        
        e.g:
        192.168.1.100:80
        192.168.1.101:8080
    '''
    
    try:
        webhosts = ""
        parsed = NmapParser.parse(scan_output)
        
        for host in parsed.hosts:
            if host.is_up():
                services = host.services
                for service in services:
                    if (service.state == "open") and (service.service[:4]) == "http":
                        webhosts += host.address+":"+str(service.port)+"\n"
        
        return webhosts
    
    except:
        print "\n[!] Error parsing scan output" 
开发者ID:isaudits,项目名称:autoenum,代码行数:25,代码来源:nmap.py

示例5: nmap_parse_live_hosts

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def nmap_parse_live_hosts(scan_output):
    '''Accepts nmap scan output XML and returns a list of all live hosts

    '''
    
    try:
        live_hosts = []
        parsed = NmapParser.parse(scan_output)
        
        for host in parsed.hosts:
            if host.is_up():
                logging.debug ("live host detected - " + host.address)
                live_hosts.append(host.address)
        
        return live_hosts
    except:
        print "\n[!] Error parsing scan output" 
开发者ID:isaudits,项目名称:autoenum,代码行数:19,代码来源:nmap.py

示例6: do_scan

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def do_scan(targets, options, fqp=None):
    parsed = None
    nm = NmapProcess(targets, options, fqp=fqp)
    rc = nm.run()
    if rc != 0:
        print("nmap scan failed: {0}".format(nm.stderr))

    try:
        parsed = NmapParser.parse(nm.stdout)
    except NmapParserException as e:
        print("Exception raised while parsing scan: {0}".format(e.msg))

    return parsed


# print scan results from a nmap report 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:18,代码来源:check_fqp_nmap.py

示例7: test_port_except

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def test_port_except(self):
        self.assertRaises(ValueError,
                          NmapParser.parse,
                          self.port_string2)
        self.assertRaises(NmapParserException,
                          NmapParser.parse,
                          self.port_string3)
        self.assertRaises(NmapParserException,
                          NmapParser.parse,
                          self.port_string4)
        self.assertRaises(NmapParserException,
                          NmapParser.parse,
                          self.port_string5)
        self.assertRaises(ValueError,
                          NmapParser.parse,
                          self.port_string6)
        self.assertRaises(NmapParserException,
                          NmapParser.parse,
                          self.port_string7)
        self.assertRaises(NmapParserException,
                          NmapParser.parse,
                          self.port_string8)
        serv = NmapParser.parse(self.port_string9)
        self.assertEqual(serv.state, None) 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:26,代码来源:test_parser.py

示例8: test_get_ports

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def test_get_ports(self):
        for testfile in self.flist:
            fd = open(testfile['file'], 'r')
            s = fd.read()
            fd.close()

            nr = NmapParser.parse(s)
            for h in nr.hosts:
                for th in self.hlist:
                    continue
# TODO FIX THIS TEST
#                    if th['hostname'] == h.hostnames[0]:
#                    self.assertEqual(th['ports'], len(h.get_ports()))
#                   self.assertEqual(th['open'], len(h.get_open_ports()))

                for np in h.get_open_ports():
                    sport = h.get_service(np[0], np[1])
                    self.assertEqual((sport.port, sport.protocol), np) 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:20,代码来源:test_report.py

示例9: test_service_not_equal

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def test_service_not_equal(self):
        for testfile in self.flist:
            fd = open(testfile['file'], 'r')
            np1 = NmapParser.parse(fd.read())
            fd.close()
            fd = open(testfile['file'], 'r')
            np2 = NmapParser.parse(fd.read())
            fd.close()

            host1 = np1.hosts.pop()
            host2 = np2.hosts.pop()
            for i in range(len(host1.services)):
                host1.services[i]._state['state'] = 'changed'
                self.assertNotEqual(host1.services[i], host2.services[i])
            #print "-----------"
            #print host1.serviceChanged(host2)
            #print "-----------" 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:19,代码来源:test_report.py

示例10: do_scan

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def do_scan(host, options):
    # uncomment line below to manually input target IP
    #host = input("Enter Target Host Address: ")
    parsed = None
    nmproc = NmapProcess(host, options)
    rc = nmproc.run()
    if rc != 0:
        print("nmap scan failed: {0}".format(nmproc.stderr))
    print(type(nmproc.stdout))

    try:
        parsed = NmapParser.parse(nmproc.stdout)
    except NmapParserException as e:
        print("Exception raised while parsing scan: {0}".format(e.msg))

    return parsed 
开发者ID:tlkh,项目名称:prowler,代码行数:18,代码来源:nmap_0.7.0_process.py

示例11: scan_ranges

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def scan_ranges(ranges, dns=None):
    '''
    Performs a list scan on the provided ranges and returns an NmapReport object
    '''
    if dns is None: 
        dns = "-sL -R" 
    else:
        dns = "-sL -R --dns-server " + dns
    logger.info('DNS Value for scan_ranges: ' + str(dns))
    logger.info('Provided Ranges for scan_ranges: ' + str(ranges))
    print("Starting nmap scan against: " + ranges)
    nm = NmapProcess(ranges, options=dns)
    rc = nm.run()
    # use the nmap parser to return an object containing all the hosts
    parsed = NmapParser.parse(nm.stdout)
    logger.info('Returning {} hosts from scan_ranges'.format(len(parsed.hosts)))
    return parsed 
开发者ID:lixmk,项目名称:Concierge,代码行数:19,代码来源:hostname-discovery.py

示例12: nmap_follow_up_scan

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def nmap_follow_up_scan(hosts, port):
    """
    This needs to be reworked.  If nmap service scan can't determine the service, i run an nmap scan without service
    detection to get the default port.  I should just read the IANA ports file instead and grep for the port, or maybe
    even the nmap version of the IANA ports list.
    :param hosts:
    :param port:
    :return:
    """
    nm = NmapProcess(hosts, options="-Pn -p %d" % port)
    rc = nm.run()
    nmap_report = NmapParser.parse(nm.stdout)
    return nmap_report 
开发者ID:sethsec,项目名称:celerystalk,代码行数:15,代码来源:utils.py

示例13: do_scan

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def do_scan(self, targets, options):
        """
        start a new nmap scan on localhost with some specific options
        :param targets:
        :param options:
        :return:
        """
        logger.info('do scan %s %s' % (targets, options))
        parsed = None
        if isinstance(options, basestring):
            options = options.encode('utf-8')
        if isinstance(targets, basestring):
            targets = targets.encode('utf-8')
        nmproc = NmapProcess(targets, options)
        rc = nmproc.run()
        if rc != 0:
            logger.error("nmap scan failed: {0}".format(nmproc.stderr))
        # print(type(nmproc.stdout))

        try:
            parsed = NmapParser.parse(nmproc.stdout)
        except NmapParserException as e:
            logger.error("Exception raised while parsing scan: {0}".format(e.msg))

        self.done_data[targets] = parsed
        return parsed

    # print scan results from a nmap report 
开发者ID:restran,项目名称:hacker-scripts,代码行数:30,代码来源:nmap_scanner.py

示例14: report

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def report(self):
        down_host=0
        for curhost in self._args.target_list:
            host_infol=self._args.coll.find({'host':curhost})
            # first print host info
            nmap_report=NmapParser.parse(str(host_infol[0]['result']))
            if nmap_report.hosts[0].status=='up':
                print '====================== '+curhost+' ======================'
                print 'Host is %s'%nmap_report.hosts[0].status
                # print ports info
                print("  PORT     STATE         SERVICE")
                for cur_info in host_infol:
                    nmap_report=NmapParser.parse(str(cur_info['result']))
                    for serv in nmap_report.hosts[0].services:
                        pserv = "{0:>5s}/{1:3s}  {2:12s}  {3}".format(
                        str(serv.port),
                        serv.protocol,
                        serv.state,
                        serv.service)
                        if len(serv.banner):
                            pserv += " ({0})".format(serv.banner)
                        print pserv
            else:
                down_host+=1
        print '=========================================================='
        print 'Not shown: '+str(down_host)+' down host'
        print '==========================================================' 
开发者ID:a7vinx,项目名称:swarm,代码行数:29,代码来源:nmap.py

示例15: do_scan

# 需要导入模块: from libnmap.parser import NmapParser [as 别名]
# 或者: from libnmap.parser.NmapParser import parse [as 别名]
def do_scan(targets, options):
    nm = NmapProcess(targets, options)
    rc = nm.run()
    if rc != 0:
        print("nmap scan failed: {0}".format(nm.stderr))

    try:
        parsed = NmapParser.parse(nm.stdout)
    except NmapParserException as e:
        print("Exception raised while parsing scan: {0}".format(e.msg))

    return parsed


# print scan results from a nmap report 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:17,代码来源:proc_nmap_like.py


注:本文中的libnmap.parser.NmapParser.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。