API Reference¶
Subpackages¶
Submodules¶
censys.api module¶
Base for interacting with the Censys Search API.
-
class
censys.api.CensysSearchAPI(api_id: Optional[str] = None, api_secret: Optional[str] = None, url: Optional[str] = 'https://censys.io/api/v1', **kwargs)[source]¶ Bases:
censys.base.CensysAPIBaseThis class is the base class for the Data, Certificate, IPv4, and Website index.
-
DEFAULT_URL: str = 'https://censys.io/api/v1'¶ Default Search API base URL.
-
INDEX_NAME: Optional[str] = None¶ Name of Censys Index.
-
account() → dict[source]¶ Gets the current account information. Including email and quota.
- Returns:
dict: Account response.
-
metadata(query: str) → dict[source]¶ Returns metadata of a given search query.
- Args:
query (str): The query to be executed.
- Returns:
dict: The metadata of the result set returned.
-
paged_search(query: str, fields: Optional[List[str]] = None, page: int = 1, flatten: bool = True) → dict[source]¶ Searches the given index for all records that match the given query.
- Args:
query (str): The query to be executed. fields (Fields, optional): Fields to be returned in the result set. page (int, optional): The page of the result set. Defaults to 1. flatten (bool, optional): Flattens fields to dot notation. Defaults to True.
- Returns:
dict: The result set returned.
-
report(query: str, field: str, buckets: int = 50) → dict[source]¶ Creates a report on the breakdown of the values of a field in a result set. For more details, see our documentation: https://censys.io/api/v1/docs/report
- Args:
query (str): The query to be executed. field (str): The field you are running a breakdown on. buckets (int, optional): The maximum number of values. Defaults to 50.
- Returns:
dict: The result set returned.
-
search(query: str, fields: Optional[List[str]] = None, page: int = 1, max_records: Optional[int] = None, flatten: bool = True) → Generator[dict, None, None][source]¶ Searches the given index for all records that match the given query. For more details, see our documentation: https://censys.io/api/v1/docs/search
- Args:
query (str): The query to be executed. fields (Fields, optional): Fields to be returned in the result set. page (int, optional): The page of the result set. Defaults to 1. max_records (Optional[int], optional): The maximum number of records. flatten (bool, optional): Flattens fields to dot notation. Defaults to True.
- Yields:
dict: The result set returned.
-
view(document_id: str) → dict[source]¶ View the current structured data we have on a specific document. For more details, see our documentation: https://censys.io/api/v1/docs/view
- Args:
document_id (str): The ID of the document you are requesting.
- Returns:
dict: The result set returned.
-
censys.base module¶
Base for interacting with the Censys API’s.
-
class
censys.base.CensysAPIBase(url: Optional[str] = None, **kwargs)[source]¶ Bases:
objectThis is the base class for API queries.
- Args:
url (str, optional): The URL to make API requests. timeout (int, optional): Timeout for API requests in seconds. user_agent (str, optional): Override User-Agent string. proxies (dict, optional): Configure HTTP proxies.
- Raises:
CensysException: Base Exception Class for the Censys API.
-
DEFAULT_MAX_RETRIES: int = 10¶ Default max number of API retries.
-
DEFAULT_TIMEOUT: int = 30¶ Default API timeout.
-
DEFAULT_USER_AGENT: str = 'censys/1.1.0'¶ Default API user agent.
censys.certificates module¶
Interact with the Censys Search Certificate API.
-
class
censys.certificates.CensysCertificates(*args, **kwargs)[source]¶ Bases:
censys.api.CensysSearchAPIInteracts with the Certificates index.
-
INDEX_NAME: Optional[str] = 'certificates'¶ Name of Censys Index.
-
MAX_PER_BULK_REQUEST= 50¶ Max number of bulk requests.
-
censys.cli module¶
Interact with the Censys Search API through the command line.
-
class
censys.cli.CensysAPISearch(**kwargs)[source]¶ Bases:
objectThis class searches the Censys API, taking in options from the command line and returning the results to a CSV or JSON file, or to stdout.
- Args:
api_id (str, optional): The API ID provided by Censys. api_secret (str, optional): The API secret provided by Censys. start_page (int, optional): Page number to start from. Defaults to 1. max_pages (int, optional): The maximum number of pages. Defaults to 10.
-
csv_fields: List[str] = []¶ A list of fields to be used by the CSV writer.
-
search_certificates(**kwargs) → List[dict][source]¶ A method to search the Certificates data set via the API.
- Args:
query (str): The string search query. fields (list, optional): The fields that should be returned with a query. overwrite (bool, optional): Whether to overwrite or append default fields
with user fields. Defaults to False.
- Returns:
Results: A list of results from the query.
-
search_ipv4(**kwargs) → List[dict][source]¶ A method to search the IPv4 data set via the API.
- Args:
query (str): The string search query. fields (list, optional): The fields that should be returned with a query. overwrite (bool, optional): Whether to overwrite or append default fields
with user fields. Defaults to False.
- Returns:
Results: A list of results from the query.
-
search_websites(**kwargs) → List[dict][source]¶ A method to search the Websites (Alexa Top 1M) data set via the API.
- Args:
query (str): The string search query. fields (list, optional): The fields that should be returned with a query. overwrite (bool, optional): Whether to overwrite or append default fields
with user fields. Defaults to False.
- Returns:
Results: A list of results from the query.
-
write_file(results_list: List[dict], file_format: str = 'screen', file_path: Optional[str] = None) → bool[source]¶ This method just sorts which format will be used to store the results of the query.
- Args:
results_list (Results): A list of results from the API query. file_format (str, optional): The format of the output. file_path (str optional): A path to write results to.
- Returns:
bool: True if wrote out successfully.
-
class
censys.cli.CensysHNRI(api_id: str, api_secret: str)[source]¶ Bases:
objectThis class searches the Censys API, check the user’s current IP for risks.
- Args:
api_id (str, optional): The API ID provided by Censys. api_secret (str, optional): The API secret provided by Censys.
-
HIGH_RISK_DEFINITION: List[str] = ['telnet', 'redis', 'postgres', 'vnc']¶
-
MEDIUM_RISK_DEFINITION: List[str] = ['ssh', 'http', 'https']¶
-
static
get_current_ip() → str[source]¶ Uses ipify.org to get the current IP address.
- Returns:
str: IP address.
-
static
risks_to_string(high_risk: list, medium_risk: list) → str[source]¶ Risks to printable string.
- Args:
high_risk (list): Lists of high risks. medium_risk (list): Lists of medium risks.
- Raises:
CensysCLIException: No information/risks found.
- Returns:
str: Printable string for CLI.
censys.config module¶
Interact with the config file.
censys.data module¶
Interact with the Censys Search Data API.
-
class
censys.data.CensysData(api_id: Optional[str] = None, api_secret: Optional[str] = None, url: Optional[str] = 'https://censys.io/api/v1', **kwargs)[source]¶ Bases:
censys.api.CensysSearchAPIInteracts with the Data index. For more details, see our documentation: https://censys.io/api/v1/docs/data
-
get_series() → dict[source]¶ Get data on the types of scans we regularly perform (series).
- Returns:
dict: The result set returned.
-
censys.exceptions module¶
Exceptions for Censys.
-
exception
censys.exceptions.CensysAPIException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysExceptionBase Exception for Censys API’s.
-
exception
censys.exceptions.CensysAppDownForMaintenanceException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the ASM API is down for maintenance.
-
exception
censys.exceptions.CensysAsmException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAPIExceptionBase Exception for the Censys ASM API.
-
exception
censys.exceptions.CensysAssociatedAssetsThresholdWarningException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the associated asset count is within the warning threshold.
-
exception
censys.exceptions.CensysCLIException[source]¶ Bases:
censys.exceptions.CensysExceptionException raised when the CLI is passed invalid arguments.
-
exception
censys.exceptions.CensysCannotCreateTagWithNewColorException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the specified tag cannot be created with a new color.
-
exception
censys.exceptions.CensysCannotRemoveNonExistentSeedsException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when trying to remove non existent seed nodes.
-
exception
censys.exceptions.CensysCannotRemoveNonSeedsException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when trying to remove non seed nodes.
-
exception
censys.exceptions.CensysCertificateNotFoundException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the certificate is not found.
-
exception
censys.exceptions.CensysCommentNotFoundException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the requested comment is not found.
-
exception
censys.exceptions.CensysDomainNotFoundException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the domain is not found.
-
class
censys.exceptions.CensysExceptionMapper[source]¶ Bases:
objectMap status code to Exception for the ASM and Search API.
-
ASM_EXCEPTIONS: Dict[int, Type[censys.exceptions.CensysAsmException]] = {10001: <class 'censys.exceptions.CensysInvalidAPIKeyException'>, 10002: <class 'censys.exceptions.CensysInvalidAuthTokenException'>, 10007: <class 'censys.exceptions.CensysInvalidSeedDataException'>, 10008: <class 'censys.exceptions.CensysInvalidRequestException'>, 10011: <class 'censys.exceptions.CensysCannotRemoveNonSeedsException'>, 10012: <class 'censys.exceptions.CensysCannotRemoveNonExistentSeedsException'>, 10013: <class 'censys.exceptions.CensysNeedConfirmationToRemoveParentSeedsException'>, 10014: <class 'censys.exceptions.CensysSeedNotFoundException'>, 10015: <class 'censys.exceptions.CensysNotASeedException'>, 10016: <class 'censys.exceptions.CensysTooManyInputNodesException'>, 10017: <class 'censys.exceptions.CensysAssociatedAssetsThresholdWarningException'>, 10018: <class 'censys.exceptions.CensysHostNotFoundException'>, 10019: <class 'censys.exceptions.CensysDomainNotFoundException'>, 10020: <class 'censys.exceptions.CensysCertificateNotFoundException'>, 10021: <class 'censys.exceptions.CensysInvalidIPv4AddressException'>, 10025: <class 'censys.exceptions.CensysTagHasTrailingOrLeadingWhitespaceException'>, 10026: <class 'censys.exceptions.CensysTagIsEmptyStringException'>, 10027: <class 'censys.exceptions.CensysTagLabelsDifferOnlyInCasingException'>, 10028: <class 'censys.exceptions.CensysTagLabelTooLongException'>, 10029: <class 'censys.exceptions.CensysAppDownForMaintenanceException'>, 10034: <class 'censys.exceptions.CensysTagColorTooLongException'>, 10035: <class 'censys.exceptions.CensysCannotCreateTagWithNewColorException'>, 10036: <class 'censys.exceptions.CensysTagColorHasTrailingOrLeadingWhitespaceException'>, 10037: <class 'censys.exceptions.CensysInvalidColorException'>, 10038: <class 'censys.exceptions.CensysInvalidSeedTypeException'>, 10039: <class 'censys.exceptions.CensysTooManyRequestsException'>, 10040: <class 'censys.exceptions.CensysInvalidLogbookCursorException'>, 10050: <class 'censys.exceptions.CensysInvalidPageSizeException'>, 10051: <class 'censys.exceptions.CensysPageNumberOutOfRangeException'>, 10054: <class 'censys.exceptions.CensysInvalidCommentException'>, 10055: <class 'censys.exceptions.CensysCommentNotFoundException'>}¶ Map of status code to ASM Exception.
-
SEARCH_EXCEPTIONS: Dict[int, Type[censys.exceptions.CensysSearchException]] = {401: <class 'censys.exceptions.CensysUnauthorizedException'>, 403: <class 'censys.exceptions.CensysUnauthorizedException'>, 404: <class 'censys.exceptions.CensysNotFoundException'>, 429: <class 'censys.exceptions.CensysRateLimitExceededException'>}¶ Map of status code to Search Exception.
-
-
exception
censys.exceptions.CensysHostNotFoundException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the requested host is not found.
-
exception
censys.exceptions.CensysInvalidAPIKeyException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the ASM API key is invalid.
-
exception
censys.exceptions.CensysInvalidAuthTokenException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the auth token is invalid.
-
exception
censys.exceptions.CensysInvalidColorException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the specified color is invalid.
-
exception
censys.exceptions.CensysInvalidCommentException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the comment is invalid.
-
exception
censys.exceptions.CensysInvalidIPv4AddressException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the IPv4 address is invalid.
-
exception
censys.exceptions.CensysInvalidLogbookCursorException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the logbook cursor is invalid.
-
exception
censys.exceptions.CensysInvalidPageSizeException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the page size is invalid.
-
exception
censys.exceptions.CensysInvalidRequestException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the HTTP request is invalid.
-
exception
censys.exceptions.CensysInvalidSeedDataException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the seed data is invalid.
-
exception
censys.exceptions.CensysInvalidSeedTypeException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the seed type is invalid.
-
exception
censys.exceptions.CensysJSONDecodeException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysSearchExceptionException raised when the resource requested is not valid JSON.
-
exception
censys.exceptions.CensysMissingApiKeyException[source]¶ Bases:
censys.exceptions.CensysExceptionException raised when there is no provided ASM API key.
-
exception
censys.exceptions.CensysNeedConfirmationToRemoveParentSeedsException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when confirmation is needed to remove seeds with children.
-
exception
censys.exceptions.CensysNotASeedException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the requested resource is not a seed.
-
exception
censys.exceptions.CensysNotFoundException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysSearchExceptionException raised when the resource requested is not found.
-
exception
censys.exceptions.CensysPageNumberOutOfRangeException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the requested page number is out of range [1 - totalPages].
-
exception
censys.exceptions.CensysRateLimitExceededException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysSearchExceptionException raised when your Censys rate limit has been exceeded.
-
exception
censys.exceptions.CensysSearchException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAPIExceptionBase Exception for the Censys search API.
-
exception
censys.exceptions.CensysSeedNotFoundException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the requested seed can not be found.
-
exception
censys.exceptions.CensysTagColorHasTrailingOrLeadingWhitespaceException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the specified tag color has trailing or leading whitespace.
-
exception
censys.exceptions.CensysTagColorTooLongException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the specified tag color is too long.
-
exception
censys.exceptions.CensysTagHasTrailingOrLeadingWhitespaceException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the specified tag has trailing or leading whitespace.
-
exception
censys.exceptions.CensysTagIsEmptyStringException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the specified tag is an empty string.
-
exception
censys.exceptions.CensysTagLabelTooLongException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the specified tag label is too long.
-
exception
censys.exceptions.CensysTagLabelsDifferOnlyInCasingException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the specified tag differs from an existing tag in only casing.
-
exception
censys.exceptions.CensysTooManyInputNodesException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when there are too many input nodes.
-
exception
censys.exceptions.CensysTooManyRequestsException(status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None)[source]¶ Bases:
censys.exceptions.CensysAsmExceptionException raised when the allowed requests bandwidth is exceeded.
Bases:
censys.exceptions.CensysSearchExceptionException raised when your Censys account doesn’t have access to the requested resource.
censys.ipv4 module¶
Interact with the Censys Search IPv4 API.
-
class
censys.ipv4.CensysIPv4(api_id: Optional[str] = None, api_secret: Optional[str] = None, url: Optional[str] = 'https://censys.io/api/v1', **kwargs)[source]¶ Bases:
censys.api.CensysSearchAPIInteracts with the IPv4 index.
-
INDEX_NAME: Optional[str] = 'ipv4'¶ Name of Censys Index.
-
censys.websites module¶
Interact with the Censys Search Website API.
-
class
censys.websites.CensysWebsites(api_id: Optional[str] = None, api_secret: Optional[str] = None, url: Optional[str] = 'https://censys.io/api/v1', **kwargs)[source]¶ Bases:
censys.api.CensysSearchAPIInteracts with the IPv4 index.
-
INDEX_NAME: Optional[str] = 'websites'¶ Name of Censys Index.
-