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


Python PortScanner.all_hosts方法代码示例

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


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

示例1: check_passive_port_task

# 需要导入模块: from nmap import PortScanner [as 别名]
# 或者: from nmap.PortScanner import all_hosts [as 别名]
def check_passive_port_task(request, module_key):

    module = Module.objects.get(id=module_key)
    debug(module, ("begin",))
    events = ModuleEvent.objects.filter(module=module).filter(back_at=None)

    portscanner = PortScanner()
    result = None
    try:
        if not module.check_port:
            raise Exception("Improperly configured")
        portscanner.scan(arguments = NMAP_ARGS, ports=str(module.check_port), hosts=module.host.encode('ascii','ignore'))

        now = datetime.datetime.now()

        host = portscanner.all_hosts()[0]
        if 'open' == portscanner[host]['tcp'][module.check_port]['state']:
            debug(module, "Port open")
            for event in events:
                event.back_at = now
                event.save()
                debug(module,"Site is back online %s" % module.name)
        else:
            if not events:
                _create_new_event(module, "off-line", now, None, "Port is closed")

    except KeyError, e:
        pass
开发者ID:BackOfficeCoPT,项目名称:site-status,代码行数:30,代码来源:views.py

示例2: run

# 需要导入模块: from nmap import PortScanner [as 别名]
# 或者: from nmap.PortScanner import all_hosts [as 别名]
    def run(self):
        try:
            from nmap import __version__
        except ImportError:
            from nmap import __version__
            self.__communicate.finishScan.emit([])
            return

        from nmap import PortScanner
        self.__targets = []
        nm = PortScanner()
        host = self.__host
        arguments = self.__arguments
        nm.scan(host, arguments=arguments)

        for host in nm.all_hosts():
            for proto in nm[host].all_protocols():
                ports = list(nm[host][proto].keys())
                ports.sort()
                for port in ports:
                    target = Target(protocol=proto,
                                    port=port,
                                    name=nm[host][proto][port]['name'],
                                    state=nm[host][proto][port]['state'],
                                    product=nm[host][proto][port]['product'],
                                    info=nm[host][proto][port]['extrainfo'],
                                    version=nm[host][proto][port]['version'])

                    self.__targets.append(target)

        self.__communicate.finishScan.emit(self.__targets)
开发者ID:DaniLabs,项目名称:rexploit,代码行数:33,代码来源:scanthread.py

示例3: run

# 需要导入模块: from nmap import PortScanner [as 别名]
# 或者: from nmap.PortScanner import all_hosts [as 别名]
    def run(self):
        """Scan the network for MAC addresses and keep tabs on which devices
            are present or have left"""

        nm = PortScanner()

        while self.running:

            # Decrement all hosts
            for mac in self.macs:
                if self.macs[mac] > 0:
                    self.macs[mac] -= 1;

            nm.scan(hosts = self.local_net, arguments = self.nmap_args)

            # Mark each host found as present unless it is not tracked
            for host in nm.all_hosts():
                try:
                    mac = nm[host]['addresses']['mac']
                    if mac in self.macs:
                        self.macs[mac] = self.timeout + 1 # Immediately decremented
                except KeyError:
                    # nmap didn't get the MAC?
                    # Just ignore it I guess
                    pass
开发者ID:reynoldsbd3,项目名称:whoshome,代码行数:27,代码来源:networkscanner.py

示例4: main

# 需要导入模块: from nmap import PortScanner [as 别名]
# 或者: from nmap.PortScanner import all_hosts [as 别名]
def main(argv):

    iprange = None

    try:
        opts, args = getopt.gnu_getopt(argv,"i:",["iprange="])
    except getopt.GetoptError:
        print sys.argv[0]+' -i <iprange>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print sys.argv[0]+' -i <iprange>'
            sys.exit()
        elif opt in ("-i", "--iprange"):
            iprange = arg

    if iprange is None:
        print sys.argv[0]+' -i <iprange>'
        sys.exit()

    scan_port = int(cfg.getConfigValue('pdu', 'scan_port'))
    snmp_port = int(cfg.getConfigValue('pdu', 'snmp_port'))
    ro_community = cfg.getConfigValue('pdu', 'ro_community')
    rw_community = cfg.getConfigValue('pdu', 'rw_community')
    dccode = cfg.getConfigValue('pdu', 'dccode')
    url = '%s/pdu/update' % cfg.getConfigValue('pdu', 'api_base')

    nm = PortScanner()
    nm.scan(hosts=iprange, arguments='-n -p %s' % (scan_port))

    for host in nm.all_hosts():
        state = nm[host]['tcp'][scan_port]['state']
        t = Thread(target=probePdu, args=(host, state, snmp_port, ro_community, rw_community, dccode, url))
        t.start()
开发者ID:DiData,项目名称:pdumgr,代码行数:36,代码来源:pdumgr.py

示例5: NmapParser

# 需要导入模块: from nmap import PortScanner [as 别名]
# 或者: from nmap.PortScanner import all_hosts [as 别名]
class NmapParser(TestPlugin):
    def __init__(self):
        self.tool_name = "nmap"
        super(NmapParser, self).__init__("nmap")
        self.nm = PortScanner()
        self.hosts = None
        self.ports = None
        self.argments = "-sV"
        self.resultparser = ResultPlugin()

    def args_status(self):
        print "hosts:", self.hosts, "\n"
        print "ports:", self.ports, "\n"
        print "argments:", self.argments, "\n"

    def start_scan(self):
        if self.hosts is not None:
            self.nm.scan(self.hosts, arguments=self.argments)
            if self.ports is not None:
                self.nm.scan(self.hosts, self.ports, arguments=self.argments)
        else:
            print "please set hosts"

    def scan_result(self):
        if self.hosts is not None and self.nm.all_hosts():
            return self.nm[self.hosts]

    def run(self):
        super(NmapParser, self).run()
        print "scanning .................\n", "please wait!\n"
        self.start_scan()

    def status(self):
        self.args_status()

    def result(self):
        if self.scan_result() is not None:
            self.resultparser.set_hostname(self.scan_result().hostname())
            self.resultparser.set_state(self.scan_result().state())
            self.resultparser.set_address(self.hosts)
            self.resultparser.set_openports(self.scan_result().all_tcp())
            if u"tcp" in self.scan_result():
                self.resultparser.set_servers(self.scan_result()[u"tcp"])

            print "hostname:", self.resultparser.get_hostname
            print "address:", self.resultparser.get_address
            print "state is :", self.resultparser.get_state
            print "open ports:", self.resultparser.get_openports
            print "servers:", self.resultparser.get_servers, "\n"

    def set_arg(self, arg1, arg2):
        if arg1 == "hosts":
            self.hosts = arg2
        elif arg1 == "ports":
            self.ports = arg2
        elif arg1 == "argments":
            self.argments = arg2
开发者ID:nolol,项目名称:coffesploit,代码行数:59,代码来源:nmapparser.py

示例6: scan

# 需要导入模块: from nmap import PortScanner [as 别名]
# 或者: from nmap.PortScanner import all_hosts [as 别名]
    def scan(self, bot, update, args):
        chat_id = update.message.chat_id
        from_user = update.message.from_user.username

        parser = ArgumentParser(prog='nmap_plugin')
        parser.add_argument('-host', required=True)
        parser.add_argument('-ports', required=False, default=None)
        parser.add_argument('-all', required=False, default=False, type=bool)
        parser.add_argument('-raw', required=False, default=None)
        try:
            p = parser.parse_args(args)
            for param in vars(p):
                if self.__check_for_idiot_friends(getattr(p, param)):
                    bot.sendMessage(
                        chat_id,
                        text='{} you are a funny guy... but go to try to be an h4x0r somewhere else.'.format(from_user)
                    )
                    if from_user == 'dzonerzy':
                        bot.sendMessage(chat_id,
                                        text='Amico del jaguaro... Ti fo un rutto ne `i viso che ti fo diventa` bello!'
                                        )
                    return
        except ArgumentError:
            bot.sendMessage(chat_id, text="Wrong parameters passed.")
            return

        arguments = '-sV'
        if p.all is True:
            arguments = '-A'

        bot.sendMessage(chat_id, text="Command accepted, running nmap against: {}".format(p.host))
        nm = PortScanner()
        nm.scan(hosts=p.host, ports=p.ports, arguments=arguments)

        msg = ''
        for host in nm.all_hosts():
            msg = '----------------------------------------------------\n'
            msg += 'Host: {} ({})\n'.format(host, nm[host].hostname())
            msg += 'State: {}\n'.format(nm[host].state())
            for proto in nm[host].all_protocols():
                msg += 'Protocol : {}\n'.format(proto)
                lport = nm[host][proto].keys()
                lport.sort()
                for port in lport:
                    msg += '\tport : {}\tstate : {}\n'.format(port, nm[host][proto][port]['state'])
        msg = 'Empty response object received.' if msg == '' else msg
        bot.sendMessage(chat_id, text=msg)
开发者ID:blackms,项目名称:myTelegramBot,代码行数:49,代码来源:nmap_plugin.py

示例7: NmapParser

# 需要导入模块: from nmap import PortScanner [as 别名]
# 或者: from nmap.PortScanner import all_hosts [as 别名]
class NmapParser(ScanPlugin):
    def __init__(self):
        self.tool_name = "nmap"
        super(NmapParser, self).__init__("nmap")
        self.nm = PortScanner()
        self.hosts = None
        self.ports = None
        self.arguments = "-sV"
        self.resultparser = ResultPlugin()

    def start_scan(self):
        if self.hosts is not None:
            self.nm.scan(self.hosts, arguments=self.arguments)
            if self.ports is not None:
                self.nm.scan(self.hosts, self.ports, arguments=self.arguments)
        else:
            print 'please set hosts'
            
    def scan_result(self):
        if self.hosts is not None and self.nm.all_hosts():
            return self.nm[self.hosts]
    
    def run(self, status):
        if status and len(status) == 3:
            self.hosts = status['hosts']
            self.ports = status['ports']
            self.arguments = status['arguments']
        super(NmapParser, self).run(status)
        print "scanning .................\n", "please wait!\n"
        self.start_scan()
        
    def status(self):
        return {"hosts": self.hosts, "ports": self.ports, "arguments": self.arguments}

    def result(self):
        if self.scan_result() is not None:
            self.resultparser.set_hostname(self.scan_result().hostname())
            self.resultparser.set_state(self.scan_result().state())
            self.resultparser.set_address(self.hosts)
            self.resultparser.set_openports(self.scan_result().all_tcp())
            if u'tcp' in self.scan_result():
                self.resultparser.set_servers(self.scan_result()[u'tcp'])
            self.resultparser.log_result()
        return self.scan_result()
开发者ID:Mithrilwoodrat,项目名称:coffesploit,代码行数:46,代码来源:nmapparser.py

示例8: host_discovery

# 需要导入模块: from nmap import PortScanner [as 别名]
# 或者: from nmap.PortScanner import all_hosts [as 别名]
def host_discovery(network_address):

    """
    Tramite il modulo nmap viene effettuata una ricerca degli host
    attivi in rete. Ritorna una lista degli host attivi in rete.
    """

    scanner = PortScanner()

    if network_address:
        print("Searching for hosts on %s..." % network_address)

    scanner.scan(hosts=network_address, arguments='-sP')

    iplist = [ip for ip in scanner.all_hosts() 
              if scanner[ip].state() == 'up']

    print("Found %s host(s)" % len(iplist))
    print(iplist)

    return iplist
开发者ID:michelesr,项目名称:network-monitor-server,代码行数:23,代码来源:scan.py


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