How to use the passivetotal.api.Client function in passivetotal

To help you get started, we’ve selected a few passivetotal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github passivetotal / python_api / passivetotal / cli / info.py View on Github external
def main():
    parser = ArgumentParser()
    subs = parser.add_subparsers(dest='cmd')

    account = subs.add_parser('account')
    account.add_argument('--json', '-j', action="store_true",
                         help="Output as JSON")
    sources = subs.add_parser('sources')
    sources.add_argument('--json', '-j', action="store_true",
                         help="Output as JSON")
    organization = subs.add_parser('organization')
    organization.add_argument('--json', '-j', action="store_true",
                              help="Output as JSON")
    args = parser.parse_args()

    client = Client.from_config()
    try:
        if args.cmd == 'account':
            data = client.get_account_details()
        if args.cmd == 'sources':
            data = client.get_account_sources()
        if args.cmd == 'organization':
            data = client.get_account_organization()
    except ValueError as e:
        parser.print_usage()
        sys.stderr.write('{}\n'.format(str(e)))
        sys.exit(1)

    if args.json:
        print(json.dumps(data, indent=4))
    else:
        print(data)
github passivetotal / python_api / passivetotal / libs / enrichment.py View on Github external
#!/usr/bin/env python
"""PassiveTotal API Interface."""

__author__ = 'Brandon Dixon (PassiveTotal)'
__version__ = '1.0.0'

from passivetotal.api import Client


class EnrichmentRequest(Client):

    """Client to interface with the enrichment calls from the PassiveTotal API."""

    def __init__(self, *args, **kwargs):
        """Setup the primary client instance."""
        super(EnrichmentRequest, self).__init__(*args, **kwargs)

    def get_enrichment(self, **kwargs):
        """Get enrichment data for a value.

        Reference: https://api.passivetotal.org/api/docs/#api-Enrichment-GetV2EnrichmentQuery

        :param query: Value to enrich
        :return: Dict of results
        """
        return self._get('enrichment', '', **kwargs)
github passivetotal / python_api / passivetotal / libs / whois.py View on Github external
#!/usr/bin/env python
"""PassiveTotal API Interface."""

__author__ = 'Brandon Dixon (PassiveTotal)'
__version__ = '1.0.0'

from passivetotal.api import Client
# exceptions
from passivetotal.common.exceptions import MISSING_FIELD
from passivetotal.common.exceptions import INVALID_FIELD_TYPE
# const
from passivetotal.common.const import WHOIS_VALID_FIELDS


class WhoisRequest(Client):

    """Client to interface with the WHOIS calls from the PassiveTotal API."""

    def __init__(self, *args, **kwargs):
        """Inherit from the base class."""
        super(WhoisRequest, self).__init__(*args, **kwargs)

    def get_whois_details(self, **kwargs):
        """Get WHOIS details based on query value.

        Reference: https://api.passivetotal.org/api/docs/#api-WHOIS-GetV2WhoisQuery

        :param str query: Query value to use when making the request for data
        :param str compact_record: Return the record in a compact format
        :return: WHOIS details for the query
        """
github passivetotal / python_api / passivetotal / libs / actions.py View on Github external
# const
from passivetotal.common.const import ACTIONS
from passivetotal.common.const import ACTIONS_CLASSIFICATION
from passivetotal.common.const import ACTIONS_DYNAMIC_DNS
from passivetotal.common.const import ACTIONS_EVER_COMPROMISED
from passivetotal.common.const import ACTIONS_MONITOR
from passivetotal.common.const import ACTIONS_SINKHOLE
from passivetotal.common.const import ACTIONS_TAG
from passivetotal.common.const import CLASSIFICATION_VALID_VALUES
from passivetotal.common.const import ENRICHMENT

__author__ = 'Brandon Dixon (PassiveTotal)'
__version__ = '1.0.0'


class ActionsClient(Client):

    """Client to interface with the Actions calls from the PassiveTotal API."""

    def __init__(self, *args, **kwargs):
        """Setup the primary client instance."""
        super(ActionsClient, self).__init__(*args, **kwargs)

    def get_dynamic_dns_status(self, **kwargs):
        return self._get(ACTIONS, ACTIONS_DYNAMIC_DNS, **kwargs)

    def set_dynamic_dns_status(self, **kwargs):
        if 'status' not in kwargs:
            raise MISSING_FIELD("Status field is required.")
        # if type(kwargs['status']) != bool:
        #     raise INVALID_VALUE_TYPE("Status must be type bool.")
        data = {'status': kwargs['status'], 'query': kwargs['query']}
github passivetotal / python_api / passivetotal / libs / ssl.py View on Github external
#!/usr/bin/env python
"""PassiveTotal API Interface."""
from passivetotal.common import utilities
from passivetotal.api import Client
# exceptions
from passivetotal.common.exceptions import MISSING_FIELD
from passivetotal.common.exceptions import INVALID_FIELD_TYPE
# const
from passivetotal.response import Response
from passivetotal.common.const import SSL_VALID_FIELDS
__author__ = 'Brandon Dixon (PassiveTotal)'
__version__ = '1.0.0'


class SslRequest(Client):

    """Client to interface with the SSL calls from the PassiveTotal API."""

    def __init__(self, *args, **kwargs):
        """Setup the primary client instance."""
        super(SslRequest, self).__init__(*args, **kwargs)

    def get_ssl_certificate_details(self, **kwargs):
        """Get SSL certificate details based on query value.

        Reference: https://api.passivetotal.org/api/docs/#api-SSL_Certificates-GetSslCertificateQuery

        :param str query: SHA-1 or IP address
        :param str compact_record: Return the record in a compact format
        :return: SSL certificate details for the query
        """
github passivetotal / python_api / passivetotal / libs / attributes.py View on Github external
#!/usr/bin/env python
"""PassiveTotal API Interface."""

__author__ = 'Brandon Dixon (PassiveTotal)'
__version__ = '1.0.0'

from passivetotal.common.const import ATTRIBUTE_APPROVED_FIELDS as approved_fields
from passivetotal.api import Client
from passivetotal.response import Response
from passivetotal.common import utilities


class AttributeRequest(Client):

    """Client to interface with the account calls from the PassiveTotal API."""

    def __init__(self, *args, **kwargs):
        """Setup the primary client instance."""
        super(AttributeRequest, self).__init__(*args, **kwargs)

    def get_host_attribute_trackers(self, **kwargs):
        """Get trackers associated with a particular host or IP address.

        Reference: https://api.passivetotal.org/api/docs/#api-Host_Attributes-GetTrackers

        :return: Dict of results with tracking IDs
        """
        return self._get('host-attributes', 'trackers', **kwargs)
github passivetotal / python_api / passivetotal / api.py View on Github external
def _get(self, endpoint, action, *url_args, **url_params):
        """Request API Endpoint - for GET methods.

        :param str endpoint: Endpoint
        :param str action: Endpoint Action
        :param url_args: Additional endpoints(for endpoints that take part of
                         the url as option)
        :param url_params: Parameters to pass to url, typically query string
        :return: response deserialized from JSON
        """
        api_url = self._endpoint(endpoint, action, *url_args)
        kwargs = {'headers': self.headers, 'params': url_params,
                  'timeout': Client.TIMEOUT, 'verify': self.verify,
                  'auth': (self.username, self.api_key)}
        if self.proxies:
            kwargs['proxies'] = self.proxies
        self.logger.debug("Requesting: %s, %s" % (api_url, str(kwargs)))
        response = requests.get(api_url, **kwargs)
        return self._json(response)
github passivetotal / python_api / passivetotal / libs / dns.py View on Github external
#!/usr/bin/env python
"""PassiveTotal API Interface."""
from passivetotal.api import Client
from passivetotal.response import Response
from passivetotal.common import utilities
from passivetotal.common.const import DNS_APPROVED_FIELDS as approved_fields

__author__ = 'Brandon Dixon (PassiveTotal)'
__version__ = '1.0.0'


class DnsRequest(Client):

    """Client to interface with the DNS calls from the PassiveTotal API."""

    def __init__(self, *args, **kwargs):
        """Inherit from the base class."""
        super(DnsRequest, self).__init__(*args, **kwargs)

    def get_passive_dns(self, **kwargs):
        """Get passive DNS data based on a query value.

        Reference: https://api.passivetotal.org/api/docs/#api-DNS-GetDnsPassiveQuery

        :param str query: Query value to use when making the request for data
        :param str start: Starting period for record filtering
        :param str end: Ending period for record filtering
        :param int timeout: Timeout to apply to source queries
github passivetotal / python_api / passivetotal / libs / account.py View on Github external
#!/usr/bin/env python
"""PassiveTotal API Interface."""

__author__ = 'Brandon Dixon (PassiveTotal)'
__version__ = '1.0.0'

from passivetotal.api import Client


class AccountClient(Client):

    """Client to interface with the account calls from the PassiveTotal API."""

    def __init__(self, *args, **kwargs):
        """Setup the primary client instance."""
        super(AccountClient, self).__init__(*args, **kwargs)

    def get_account_details(self):
        """Get details about the requesting account.

        Reference: https://api.passivetotal.org/api/docs/#api-Account-GetAccount

        :return: Dict of account data
        """
        return self._get('account', '')