Exemplo n.º 1
0
def write_output(results, arguments):
    """Format data based on the type.

    :param results: Result data from one of the various calls
    :param arguments: Supplied arguments from the CLI
    :return: Formatted list of output data
    """
    if arguments.cmd == 'pdns':
        if not arguments.format:
            arguments.format = 'table'
        if not arguments.unique:
            data = DnsResponse.process(results)
        else:
            data = DnsUniqueResponse.process(results)

        data = [getattr(data, arguments.format)]

    elif arguments.cmd == 'whois':
        if not arguments.format:
            arguments.format = 'text'
        if not arguments.field:
            tmp = WhoisResponse.process(results)
            data = [getattr(tmp, arguments.format)]
        else:
            data = list()
            results = WhoisSearchResponse(results)
            for record in results.get_records():
                data.append(getattr(record, arguments.format))

    elif arguments.cmd == 'ssl':
        if not arguments.format:
            arguments.format = 'text'
        if not arguments.type:
            tmp = SslResponse.process(results)
            data = [getattr(tmp, arguments.format)]
        elif arguments.type == 'search':
            data = list()
            for record in results.get('records', []):
                tmp = SslResponse.process(record)
                data.append(getattr(tmp, arguments.format))
        else:
            tmp = SslHistoryResponse.process(results)
            data = [getattr(tmp, arguments.format)]

    elif arguments.cmd == 'attribute':
        if not arguments.format:
            arguments.format = 'table'
        tmp = AttributeResponse.process(results)
        data = [getattr(tmp, arguments.format)]

    else:
        return [str(results)]

    return data
Exemplo n.º 2
0
import sys
from passivetotal.libs.dns import DnsRequest
from passivetotal.libs.dns import DnsUniqueResponse
from passivetotal.libs.whois import WhoisRequest
from passivetotal.libs.whois import WhoisResponse
from passivetotal.common.utilities import is_ip

query = sys.argv[1]
if not is_ip(query):
    raise Exception("This script only accepts valid IP addresses!")
    sys.exit(1)

# look up the unique resolutions
client = DnsRequest.from_config()
raw_results = client.get_unique_resolutions(query=query)
loaded = DnsUniqueResponse(raw_results)

whois_client = WhoisRequest.from_config()
for record in loaded.get_records()[:3]:
    raw_whois = whois_client.get_whois_details(query=record.resolve)
    whois = WhoisResponse(raw_whois)
    print record.resolve, whois.contactEmail