@@ -35,12 +35,11 @@ class CensysAPISearch:
3535 This class searches the Censys API, taking in options from the command line and
3636 returning the results to a CSV or JSON file, or to stdout.
3737
38- Kwargs:
39- format (str): Format of results: CSV, JSON, or stdout.
40- start_page (int): Page number to start from.
41- max_pages (int): The maximum number of pages of results to return.
42- api_secret (str): An API secret provided by Censys.
43- api_id (str): An API ID provided by Censys.
38+ Args:
39+ api_id (str, optional): The API ID provided by Censys.
40+ api_secret (str, optional): The API secret provided by Censys.
41+ start_page (int, optional): Page number to start from. Defaults to 1.
42+ max_pages (int, optional): The maximum number of pages. Defaults to 10.
4443 """
4544
4645 csv_fields : Fields = list ()
@@ -49,7 +48,6 @@ class CensysAPISearch:
4948 def __init__ (self , ** kwargs ):
5049 self .api_user = kwargs .get ("api_id" )
5150 self .api_pass = kwargs .get ("api_secret" )
52-
5351 self .start_page = kwargs .get ("start_page" , 1 )
5452 self .max_pages = kwargs .get ("max_pages" , 10 )
5553
@@ -88,8 +86,8 @@ def _write_json(file_path: str, search_results: Results) -> bool:
8886 This method writes the search results to a new file in JSON format.
8987
9088 Args:
91- file_path (str): name of the file to write to on the disk.
92- search_results (Results): list of search results from API query.
89+ file_path (str): Name of the file to write to on the disk.
90+ search_results (Results): A list of results from the query.
9391
9492 Returns:
9593 bool: True if wrote to file successfully.
@@ -193,9 +191,9 @@ def _process_search(
193191 This method provides a common way to process searches from the API.
194192
195193 Args:
196- query: The string to send to the API as a query.
197- search_index: The data set to be queried - IPv4, Website, or Certificates .
198- fields: A list of fields to be returned for each result.
194+ query (str) : The string to send to the API as a query.
195+ search_index (Index) : The data set to be queried.
196+ fields (Fields) : A list of fields to be returned for each result.
199197
200198 Returns:
201199 Results: A list of results from the query.
@@ -226,10 +224,11 @@ def search_ipv4(self, **kwargs) -> Results:
226224 """
227225 A method to search the IPv4 data set via the API.
228226
229- Kwargs:
230- query: The string search query.
231- fields: The fields that should be returned with a query.
232- overwrite: Overwrite the default list of fields with the given fields.
227+ Args:
228+ query (str): The string search query.
229+ fields (list, optional): The fields that should be returned with a query.
230+ overwrite (bool, optional): Whether to overwrite or append default fields
231+ with user fields. Defaults to False.
233232
234233 Returns:
235234 Results: A list of results from the query.
@@ -270,10 +269,10 @@ def search_certificates(self, **kwargs) -> Results:
270269 A method to search the Certificates data set via the API.
271270
272271 Args:
273- kwargs:
274- query : The string search query.
275- fields: The fields that should be returned with a query.
276- overwrite: Overwrite the default list of fields with the given fields.
272+ query (str): The string search query.
273+ fields (list, optional) : The fields that should be returned with a query.
274+ overwrite (bool, optional): Whether to overwrite or append default fields
275+ with user fields. Defaults to False .
277276
278277 Returns:
279278 Results: A list of results from the query.
@@ -311,10 +310,10 @@ def search_websites(self, **kwargs) -> Results:
311310 A method to search the Websites (Alexa Top 1M) data set via the API.
312311
313312 Args:
314- kwargs:
315- query : The string search query.
316- fields: The fields that should be returned with a query.
317- overwrite: Overwrite the default list of fields with the given fields.
313+ query (str): The string search query.
314+ fields (list, optional) : The fields that should be returned with a query.
315+ overwrite (bool, optional): Whether to overwrite or append default fields
316+ with user fields. Defaults to False .
318317
319318 Returns:
320319 Results: A list of results from the query.
@@ -347,9 +346,9 @@ class CensysHNRI:
347346 """
348347 This class searches the Censys API, check the user's current IP for risks.
349348
350- Kwargs :
351- api_secret (str): An API secret provided by Censys.
352- api_id (str): An API ID provided by Censys.
349+ Args :
350+ api_id (str, optional ): The API ID provided by Censys.
351+ api_secret (str, optional ): The API secret provided by Censys.
353352 """
354353
355354 HIGH_RISK_DEFINITION : List [str ] = ["telnet" , "redis" , "postgres" , "vnc" ]
@@ -476,10 +475,7 @@ def search(args):
476475 args (Namespace): Argparse Namespace.
477476 """
478477
479- censys_args = {"query" : args .query }
480-
481- if args .fields :
482- censys_args ["fields" ] = args .fields
478+ censys_args = {}
483479
484480 if args .start_page :
485481 censys_args ["start_page" ] = args .start_page
@@ -493,11 +489,16 @@ def search(args):
493489 if args .api_secret :
494490 censys_args ["api_secret" ] = args .api_secret
495491
496- if args .overwrite :
497- censys_args ["overwrite" ] = args .overwrite
498-
499492 censys = CensysAPISearch (** censys_args )
500493
494+ search_args = {"query" : args .query }
495+
496+ if args .fields :
497+ search_args ["fields" ] = args .fields
498+
499+ if args .overwrite :
500+ search_args ["overwrite" ] = args .overwrite
501+
501502 indexes = {
502503 "ipv4" : censys .search_ipv4 ,
503504 "certs" : censys .search_certificates ,
@@ -507,7 +508,7 @@ def search(args):
507508 index_type = args .index_type or args .query_type
508509
509510 index_func = indexes [index_type ]
510- results = index_func (** censys_args )
511+ results = index_func (** search_args )
511512
512513 try :
513514 censys .write_file (results , file_format = args .format , file_path = args .output )
0 commit comments