Exemplo n.º 1
0
def mtgx2csv(opts):

    zipfile = ZipFile(opts.graph)
    graphs = filter(lambda x: x.endswith('.graphml'), zipfile.namelist())

    for f in graphs:
        filename = '%s_%s' % (opts.graph.replace(
            '.', '_', 1), os.path.basename(f).replace('.graphml', '.csv', 1))
        print 'Writing data from %s/%s to %s...' % (opts.graph, f, filename)
        with open(filename, 'wb') as csvfile:
            csv = writer(csvfile)
            xml = XML(zipfile.open(f).read())
            links = {}
            for edge in xml.findall(
                    '{http://graphml.graphdrawing.org/xmlns}graph/'
                    '{http://graphml.graphdrawing.org/xmlns}edge'):
                src = edge.get('source')
                dst = edge.get('target')
                if src not in links:
                    links[src] = dict(in_=0, out=0)
                if dst not in links:
                    links[dst] = dict(in_=0, out=0)
                links[src]['out'] += 1
                links[dst]['in_'] += 1

            for node in xml.findall(
                    '{http://graphml.graphdrawing.org/xmlns}graph/'
                    '{http://graphml.graphdrawing.org/xmlns}node'):

                node_id = node.get('id')
                node = node.find(
                    '{http://graphml.graphdrawing.org/xmlns}data/'
                    '{http://maltego.paterva.com/xml/mtgx}MaltegoEntity')

                row = [to_utf8(('Entity Type=%s' % node.get('type')).strip())]
                for prop in node.findall(
                        '{http://maltego.paterva.com/xml/mtgx}Properties/'
                        '{http://maltego.paterva.com/xml/mtgx}Property'):
                    value = prop.find(
                        '{http://maltego.paterva.com/xml/mtgx}Value'
                    ).text or ''
                    row.append(
                        to_utf8(('%s=%s' %
                                 (prop.get('displayName'), value)).strip()))
                row.append('Incoming Links=%s' %
                           links.get(node_id, {}).get('in_', 0))
                row.append('Outgoing Links=%s' %
                           links.get(node_id, {}).get('out', 0))
                csv.writerow(row)
Exemplo n.º 2
0
def run(args):
    opts = parse_args(args)

    zipfile = ZipFile(opts.graph)
    graphs = filter(lambda x: x.endswith('.graphml'), zipfile.namelist())

    for f in graphs:
        with open(f.split('/')[1].split('.')[0] + '.csv', 'wb') as csvfile:
            csv = writer(csvfile)
            xml = XML(zipfile.open(f).read())
            links = {}
            for edge in xml.findall(
                    '{http://graphml.graphdrawing.org/xmlns}graph/'
                    '{http://graphml.graphdrawing.org/xmlns}edge'):
                src = edge.get('source')
                dst = edge.get('target')
                if src not in links:
                    links[src] = dict(in_=0, out=0)
                if dst not in links:
                    links[dst] = dict(in_=0, out=0)
                links[src]['out'] += 1
                links[dst]['in_'] += 1

            for node in xml.findall(
                    '{http://graphml.graphdrawing.org/xmlns}graph/'
                    '{http://graphml.graphdrawing.org/xmlns}node'):

                node_id = node.get('id')
                node = node.find(
                    '{http://graphml.graphdrawing.org/xmlns}data/'
                    '{http://maltego.paterva.com/xml/mtgx}MaltegoEntity')

                row = [to_utf8(('Entity Type=%s' % node.get('type')).strip())]
                for prop in node.findall(
                        '{http://maltego.paterva.com/xml/mtgx}Properties/'
                        '{http://maltego.paterva.com/xml/mtgx}Property'):
                    value = prop.find(
                        '{http://maltego.paterva.com/xml/mtgx}Value'
                    ).text or ''
                    row.append(
                        to_utf8(('%s=%s' %
                                 (prop.get('displayName'), value)).strip()))
                row.append('Incoming Links=%s' %
                           links.get(node_id, {}).get('in_', 0))
                row.append('Outgoing Links=%s' %
                           links.get(node_id, {}).get('out', 0))
                csv.writerow(row)
Exemplo n.º 3
0
def run(args):

    opts = parse_args(args)

    zip = ZipFile(opts.graph)
    graphs = filter(lambda x: x.endswith('.graphml'), zip.namelist())

    for f in graphs:
        csv = open(f.split('/')[1].split('.')[0] + '.csv', 'w')
        xml = XML(zip.open(f).read())
        for e in xml.findall('{http://graphml.graphdrawing.org/xmlns}graph/{http://graphml.graphdrawing.org/xmlns}node/{http://graphml.graphdrawing.org/xmlns}data/{http://maltego.paterva.com/xml/mtgx}MaltegoEntity'):
            csv.write(to_utf8(('"Entity Type=%s",' % e.get('type')).strip()))
            for prop in e.findall('{http://maltego.paterva.com/xml/mtgx}Properties/{http://maltego.paterva.com/xml/mtgx}Property'):
                value = prop.find('{http://maltego.paterva.com/xml/mtgx}Value').text or ''
                if '"' in value:
                    value.replace('"', '""')
                csv.write(to_utf8(('"%s=%s",' % (prop.get('displayName'), value)).strip().replace('\n', ', ')))
            csv.write('\n')
Exemplo n.º 4
0
def mtgx2csv(opts):

    zipfile = ZipFile(opts.graph)
    graphs = filter(lambda x: x.endswith(".graphml"), zipfile.namelist())

    for f in graphs:
        filename = "%s_%s" % (opts.graph.replace(".", "_", 1), os.path.basename(f).replace(".graphml", ".csv", 1))
        print "Writing data from %s/%s to %s..." % (opts.graph, f, filename)
        with open(filename, "wb") as csvfile:
            csv = writer(csvfile)
            xml = XML(zipfile.open(f).read())
            links = {}
            for edge in xml.findall(
                "{http://graphml.graphdrawing.org/xmlns}graph/" "{http://graphml.graphdrawing.org/xmlns}edge"
            ):
                src = edge.get("source")
                dst = edge.get("target")
                if src not in links:
                    links[src] = dict(in_=0, out=0)
                if dst not in links:
                    links[dst] = dict(in_=0, out=0)
                links[src]["out"] += 1
                links[dst]["in_"] += 1

            for node in xml.findall(
                "{http://graphml.graphdrawing.org/xmlns}graph/" "{http://graphml.graphdrawing.org/xmlns}node"
            ):

                node_id = node.get("id")
                node = node.find(
                    "{http://graphml.graphdrawing.org/xmlns}data/" "{http://maltego.paterva.com/xml/mtgx}MaltegoEntity"
                )

                row = [to_utf8(("Entity Type=%s" % node.get("type")).strip())]
                for prop in node.findall(
                    "{http://maltego.paterva.com/xml/mtgx}Properties/" "{http://maltego.paterva.com/xml/mtgx}Property"
                ):
                    value = prop.find("{http://maltego.paterva.com/xml/mtgx}Value").text or ""
                    row.append(to_utf8(("%s=%s" % (prop.get("displayName"), value)).strip()))
                row.append("Incoming Links=%s" % links.get(node_id, {}).get("in_", 0))
                row.append("Outgoing Links=%s" % links.get(node_id, {}).get("out", 0))
                csv.writerow(row)
Exemplo n.º 5
0
def mtgx2csv(opts):

    zipfile = ZipFile(opts.graph)
    graphs = filter(lambda x: x.endswith('.graphml'), zipfile.namelist())

    for f in graphs:
        filename = '%s_%s' % (opts.graph.replace('.', '_', 1), os.path.basename(f).replace('.graphml', '.csv', 1))
        print 'Writing data from %s/%s to %s...' % (opts.graph, f, filename)
        with open(filename, 'wb') as csvfile:
            csv = writer(csvfile)
            xml = XML(zipfile.open(f).read())
            links = {}
            for edge in xml.findall('{http://graphml.graphdrawing.org/xmlns}graph/'
                                    '{http://graphml.graphdrawing.org/xmlns}edge'):
                src = edge.get('source')
                dst = edge.get('target')
                if src not in links:
                    links[src] = dict(in_=0, out=0)
                if dst not in links:
                    links[dst] = dict(in_=0, out=0)
                links[src]['out'] += 1
                links[dst]['in_'] += 1

            for node in xml.findall('{http://graphml.graphdrawing.org/xmlns}graph/'
                                    '{http://graphml.graphdrawing.org/xmlns}node'):

                node_id = node.get('id')
                node = node.find('{http://graphml.graphdrawing.org/xmlns}data/'
                                 '{http://maltego.paterva.com/xml/mtgx}MaltegoEntity')

                row = [to_utf8(('Entity Type=%s' % node.get('type')).strip())]
                for prop in node.findall('{http://maltego.paterva.com/xml/mtgx}Properties/'
                                         '{http://maltego.paterva.com/xml/mtgx}Property'):
                    value = prop.find('{http://maltego.paterva.com/xml/mtgx}Value').text or ''
                    row.append(to_utf8(('%s=%s' % (prop.get('displayName'), value)).strip()))
                row.append('Incoming Links=%s' % links.get(node_id, {}).get('in_', 0))
                row.append('Outgoing Links=%s' % links.get(node_id, {}).get('out', 0))
                csv.writerow(row)
Exemplo n.º 6
0
def run(args):
    opts = parse_args(args)

    zipfile = ZipFile(opts.graph)
    graphs = filter(lambda x: x.endswith('.graphml'), zipfile.namelist())

    for f in graphs:
        with open(f.split('/')[1].split('.')[0] + '.csv', 'wb') as csvfile:
            csv = writer(csvfile)
            xml = XML(zipfile.open(f).read())
            links = {}
            for edge in xml.findall('{http://graphml.graphdrawing.org/xmlns}graph/'
                                    '{http://graphml.graphdrawing.org/xmlns}edge'):
                src = edge.get('source')
                dst = edge.get('target')
                if src not in links:
                    links[src] = dict(in_=0, out=0)
                if dst not in links:
                    links[dst] = dict(in_=0, out=0)
                links[src]['out'] += 1
                links[dst]['in_'] += 1

            for node in xml.findall('{http://graphml.graphdrawing.org/xmlns}graph/'
                                    '{http://graphml.graphdrawing.org/xmlns}node'):

                node_id = node.get('id')
                node = node.find('{http://graphml.graphdrawing.org/xmlns}data/'
                                 '{http://maltego.paterva.com/xml/mtgx}MaltegoEntity')

                row = [to_utf8(('Entity Type=%s' % node.get('type')).strip())]
                for prop in node.findall('{http://maltego.paterva.com/xml/mtgx}Properties/'
                                         '{http://maltego.paterva.com/xml/mtgx}Property'):
                    value = prop.find('{http://maltego.paterva.com/xml/mtgx}Value').text or ''
                    row.append(to_utf8(('%s=%s' % (prop.get('displayName'), value)).strip()))
                row.append('Incoming Links=%s' % links[node_id]['in_'])
                row.append('Outgoing Links=%s' % links[node_id]['out'])
                csv.writerow(row)