當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。