secutils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:secutils 作者: zkvL7 项目源码 文件源码
def getPorts(self, path):
        ports = list()
        # Recursively proceesses all nmap XML files from all specified folders 
        if len(path) > 0:
            # Obtains all nmap XML files from each folder
            p = path[0] + '*.xml'
            if (len(glob(p)) == 0):
                self.printMsg(5, "[!] [Error] There's no xml files in " + p[:-5])                    
            else:
                for f in glob(p):
                    self.printMsg(3, "Processing " + f.split(self.separator)[-1] + " ...")
                    dom = parse(f)
                    nmaprun = dom.documentElement
                    # For each host in nmap XML file
                    for node in nmaprun.getElementsByTagName('host'):
                        # Validate sif host is up & has ports node
                        if node.getElementsByTagName('status')[0].getAttribute('state') == "up" and node.getElementsByTagName('ports'):
                            # For each port in port node extracts port id if state is "open"
                            for port in node.getElementsByTagName('ports')[0].getElementsByTagName('port'):
                                if port.getElementsByTagName('state')[0].getAttribute('state') == "open":
                                    ports.append(port.getAttribute('portid'))
                    dom.unlink()
            del path[0]
            ports.extend(self.getPorts(path))
        return sorted(set(ports))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号