コード例 #1
0
ファイル: Script.py プロジェクト: f-froehlich/nmap-scan
    def from_dict(d):
        try:
            from nmap_scan.Scripts.ScriptParser import parse

            return parse(Script.dict_to_xml(d, False))
        except NmapXMLParserException:
            raise NmapDictParserException()
コード例 #2
0
ファイル: RunStats.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('runstats')
        xml_finished = etree.Element('finished')
        xml_hosts = etree.Element('hosts')
        if None != d.get('time', None):
            xml_finished.attrib['time'] = str(d.get('time', None))
        if None != d.get('timestr', None):
            xml_finished.attrib['timestr'] = d.get('timestr', None)
        if None != d.get('elapsed', None):
            xml_finished.attrib['elapsed'] = str(d.get('elapsed', None))
        if None != d.get('summary', None):
            xml_finished.attrib['summary'] = d.get('summary', None)
        if None != d.get('exit', None):
            xml_finished.attrib['exit'] = d.get('exit', None)
        if None != d.get('errormsg', None):
            xml_finished.attrib['errormsg'] = d.get('errormsg', None)

        if None != d.get('total', None):
            xml_hosts.attrib['total'] = str(d.get('total', None))
        if None != d.get('down', None):
            xml_hosts.attrib['down'] = str(d.get('down', None))
        if None != d.get('up', None):
            xml_hosts.attrib['up'] = str(d.get('up', None))

        xml.append(xml_finished)
        xml.append(xml_hosts)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #3
0
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('port')
        if None != d.get('protocol', None):
            xml.attrib['protocol'] = d.get('protocol', None)
        if None != d.get('port', None):
            xml.attrib['portid'] = str(d.get('port', None))

        if None != d.get('state', None):
            xml.append(State.dict_to_xml(d['state'], validate_xml))

        if None != d.get('owner', None):
            owner_xml = etree.Element('owner')
            owner_xml.attrib['name'] = d.get('owner', None)
            xml.append(owner_xml)

        if None != d.get('service', None):
            xml.append(Service.dict_to_xml(d['service'], validate_xml))

        if None != d.get('scripts', None):
            for script_dict in d['scripts']:
                xml.append(Script.dict_to_xml(script_dict, validate_xml))

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #4
0
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('osclass')
        if None != d.get('vendor', None):
            xml.attrib['vendor'] = d.get('vendor', None)
        if None != d.get('generation', None):
            xml.attrib['osgen'] = d.get('generation', None)
        if None != d.get('type', None):
            xml.attrib['type'] = d.get('type', None)
        if None != d.get('family', None):
            xml.attrib['osfamily'] = d.get('family', None)
        if None != d.get('accuracy', None):
            xml.attrib['accuracy'] = str(d.get('accuracy', None))

        if None != d.get('cpes', None):
            for cpe in d['cpes']:
                cpe_xml = etree.Element('cpe')
                cpe_xml.text = cpe
                xml.append(cpe_xml)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #5
0
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('elem')
        if None != d.get('key', None):
            xml.attrib['key'] = d.get('key', None)
        if None != d.get('data', None):
            xml.text = d['data']

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #6
0
ファイル: IPIDSequence.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('ipidsequence')
        if None != d.get('class', None):
            xml.attrib['class'] = d.get('class', None)
        if None != d.get('values', None):
            xml.attrib['values'] = d.get('values', None)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #7
0
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('uptime')
        if None != d.get('lastboot', None):
            xml.attrib['lastboot'] = d.get('lastboot', None)
        if None != d.get('seconds', None):
            xml.attrib['seconds'] = str(d.get('seconds', None))

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #8
0
ファイル: HostName.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('hostname')

        if None != d.get('name', None):
            xml.attrib['name'] = d.get('name', None)
        if None != d.get('type', None):
            xml.attrib['type'] = d.get('type', None)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #9
0
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('service')

        if None != d.get('name', None):
            xml.attrib['name'] = d['name']
        if None != d.get('conf', None):
            xml.attrib['conf'] = str(d['conf'])
        if None != d.get('method', None):
            xml.attrib['method'] = d['method']
        if None != d.get('version', None):
            xml.attrib['version'] = str(d['version'])
        if None != d.get('product', None):
            xml.attrib['product'] = d['product']
        if None != d.get('extrainfo', None):
            xml.attrib['extrainfo'] = d['extrainfo']
        if None != d.get('tunnel', None):
            xml.attrib['tunnel'] = d['tunnel']
        if None != d.get('proto', None):
            xml.attrib['proto'] = d['proto']
        if None != d.get('rpcnum', None):
            xml.attrib['rpcnum'] = str(d['rpcnum'])
        if None != d.get('lowver', None):
            xml.attrib['lowver'] = str(d['lowver'])
        if None != d.get('highver', None):
            xml.attrib['highver'] = str(d['highver'])
        if None != d.get('hostname', None):
            xml.attrib['hostname'] = d['hostname']
        if None != d.get('ostype', None):
            xml.attrib['ostype'] = d['ostype']
        if None != d.get('devicetype', None):
            xml.attrib['devicetype'] = d['devicetype']
        if None != d.get('servicefp', None):
            xml.attrib['servicefp'] = d['servicefp']

        if None != d.get('cpes', None):
            if None != d.get('cpes', None):
                for cpe in d['cpes']:
                    cpe_xml = etree.Element('cpe')
                    cpe_xml.text = cpe
                    xml.append(cpe_xml)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #10
0
ファイル: Time.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('times')
        if None != d.get('srtt', None):
            xml.attrib['srtt'] = d.get('srtt', None)
        if None != d.get('rttvar', None):
            xml.attrib['rttvar'] = d.get('rttvar', None)
        if None != d.get('to', None):
            xml.attrib['to'] = d.get('to', None)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #11
0
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('status')
        if None != d.get('state', None):
            xml.attrib['state'] = d.get('state', None)
        if None != d.get('reason', None):
            xml.attrib['reason'] = d.get('reason', None)
        if None != d.get('reasonttl', None):
            xml.attrib['reason_ttl'] = str(d.get('reasonttl', None))

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #12
0
ファイル: OSUsedPort.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('portused')
        if None != d.get('state', None):
            xml.attrib['state'] = d.get('state', None)
        if None != d.get('proto', None):
            xml.attrib['proto'] = d.get('proto', None)
        if None != d.get('port', None):
            xml.attrib['portid'] = str(d.get('port', None))

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #13
0
ファイル: Target.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('target')
        if None != d.get('status', None):
            xml.attrib['status'] = d.get('status', None)
        if None != d.get('reason', None):
            xml.attrib['reason'] = d.get('reason', None)
        if None != d.get('specification', None):
            xml.attrib['specification'] = d.get('specification', None)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #14
0
ファイル: TCPSequence.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('tcpsequence')
        if None != d.get('index', None):
            xml.attrib['index'] = str(d.get('index', None))
        if None != d.get('values', None):
            xml.attrib['values'] = d.get('values', None)
        if None != d.get('difficulty', None):
            xml.attrib['difficulty'] = d.get('difficulty', None)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #15
0
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('trace')
        if None != d.get('port', None):
            xml.attrib['port'] = str(d.get('port', None))
        if None != d.get('proto', None):
            xml.attrib['proto'] = d.get('proto', None)

        if None != d.get('hops', None):
            for hop_dict in d['hops']:
                xml.append(Hop.dict_to_xml(hop_dict))

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()
        return xml
コード例 #16
0
    def dict_to_xml(d, validate_xml=True):
        from lxml import etree
        xml = etree.Element('taskbegin')
        if None != d.get('task', None):
            xml.attrib['task'] = d.get('task', None)
        if None != d.get('time', None):
            xml.attrib['time'] = str(d.get('time', None))
        if None != d.get('extrainfo', None):
            xml.attrib['extrainfo'] = d.get('extrainfo', None)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #17
0
ファイル: HostAddress.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('address')

        if None != d.get('addr', None):
            xml.attrib['addr'] = d.get('addr', None)
        if None != d.get('vendor', None):
            xml.attrib['vendor'] = d.get('vendor', None)
        if None != d.get('type', None):
            xml.attrib['addrtype'] = d.get('type', None)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #18
0
ファイル: Hop.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('hop')
        if None != d.get('ip', None):
            xml.attrib['ipaddr'] = d.get('ip', None)
        if None != d.get('ttl', None):
            xml.attrib['ttl'] = str(d.get('ttl', None))
        if None != d.get('rtt', None):
            xml.attrib['rtt'] = d.get('rtt', None)
        if None != d.get('host', None):
            xml.attrib['host'] = d.get('host', None)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #19
0
ファイル: Table.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('table')
        if None != d.get('key', None):
            xml.attrib['key'] = d.get('key', None)
        if None != d.get('tables', None):
            for table_dict in d['tables']:
                xml.append(Table.dict_to_xml(table_dict, validate_xml))
        if None != d.get('elements', None):
            for element_dict in d['elements']:
                xml.append(Element.dict_to_xml(element_dict, validate_xml))

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #20
0
ファイル: ExtraReason.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('extrareasons')
        if None != d.get('reason', None):
            xml.attrib['reason'] = d.get('reason', None)
        if None != d.get('count', None):
            xml.attrib['count'] = d.get('count', None)
        if None != d.get('proto', None):
            xml.attrib['proto'] = d.get('proto', None)
        if None != d.get('ports', None):
            xml.attrib['ports'] = d.get('ports', None)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #21
0
ファイル: OSMatch.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('osmatch')
        if None != d.get('accuracy', None):
            xml.attrib['accuracy'] = str(d.get('accuracy', None))
        if None != d.get('name', None):
            xml.attrib['name'] = d.get('name', None)
        if None != d.get('line', None):
            xml.attrib['line'] = str(d.get('line', None))

        if None != d.get('osclass', None):
            for osclass_dict in d['osclass']:
                xml.append(OSClass.dict_to_xml(osclass_dict, validate_xml))

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #22
0
ファイル: ScanInfo.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('scaninfo')
        if None != d.get('type', None):
            xml.attrib['type'] = d.get('type', None)
        if None != d.get('protocol', None):
            xml.attrib['protocol'] = d.get('protocol', None)
        if None != d.get('scanflags', None):
            xml.attrib['scanflags'] = d.get('scanflags', None)
        if None != d.get('numservices', None):
            xml.attrib['numservices'] = str(d.get('numservices', None))
        if None != d.get('services', None):
            xml.attrib['services'] = d.get('services', None)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #23
0
ファイル: TaskProgress.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('taskprogress')
        if None != d.get('task', None):
            xml.attrib['task'] = d.get('task', None)
        if None != d.get('time', None):
            xml.attrib['time'] = str(d.get('time', None))
        if None != d.get('percent', None):
            xml.attrib['percent'] = str(d.get('percent', None))
        if None != d.get('remaining', None):
            xml.attrib['remaining'] = d.get('remaining', None)
        if None != d.get('etc', None):
            xml.attrib['etc'] = d.get('etc', None)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #24
0
ファイル: HostHint.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('hosthint')
        if None != d.get('statuses', None):
            for status_dict in d['statuses']:
                xml.append(Status.dict_to_xml(status_dict, validate_xml))
        if None != d.get('addresses', None):
            for address_dict in d['addresses']:
                xml.append(HostAddress.dict_to_xml(address_dict, validate_xml))
        if None != d.get('hostnames', None):
            hostnames_xml = etree.Element('hostnames')
            for hostname_dict in d['hostnames']:
                hostnames_xml.append(HostName.dict_to_xml(hostname_dict, validate_xml))
            xml.append(hostnames_xml)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #25
0
ファイル: OS.py プロジェクト: f-froehlich/nmap-scan
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('os')

        if None != d.get('portused', None):
            for portused_dict in d['portused']:
                xml.append(OSUsedPort.dict_to_xml(portused_dict, validate_xml))
        if None != d.get('osmatch', None):
            for osmatch_dict in d['osmatch']:
                xml.append(OSMatch.dict_to_xml(osmatch_dict, validate_xml))

        if None != d.get('osfingerprint', None):
            for osfingerprint in d['osfingerprint']:
                cpe_xml = etree.Element('osfingerprint')
                cpe_xml.attrib['fingerprint'] = osfingerprint
                xml.append(cpe_xml)

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
コード例 #26
0
ファイル: PingReport.py プロジェクト: f-froehlich/nmap-scan
 def from_dict(d):
     try:
         return PingReport(PingReport.dict_to_xml(d, False))
     except NmapXMLParserException:
         raise NmapDictParserException()
コード例 #27
0
ファイル: OSUsedPort.py プロジェクト: f-froehlich/nmap-scan
 def from_dict(d):
     try:
         return OSUsedPort(OSUsedPort.dict_to_xml(d, False))
     except NmapXMLParserException:
         raise NmapDictParserException()
コード例 #28
0
 def from_dict(d):
     try:
         return Uptime(Uptime.dict_to_xml(d, False))
     except NmapXMLParserException:
         raise NmapDictParserException()
コード例 #29
0
ファイル: TaskProgress.py プロジェクト: f-froehlich/nmap-scan
 def from_dict(d):
     try:
         return TaskProgress(TaskProgress.dict_to_xml(d, False))
     except NmapXMLParserException:
         raise NmapDictParserException()
コード例 #30
0
ファイル: IPIDSequence.py プロジェクト: f-froehlich/nmap-scan
 def from_dict(d):
     try:
         return IPIDSequence(IPIDSequence.dict_to_xml(d, False))
     except NmapXMLParserException:
         raise NmapDictParserException()