Skip to content

Library and Internal Component Usage

Nathan edited this page Jul 31, 2020 · 5 revisions

Library Usage

Since this library can be installed as a module, the findcdn program can be called from and implemented in your own project allowing you to take advantage of the CDN detection power of findcdn. Simply import into your project and pass your list of domains you wish to analyze. In return, you will receive a json of only domains with a CDN or all domains depending on the option you choose. The status bar and output file options are also allowed too if you wish to utilize those utilities in the tool.

The format is as follows:

findcdn.main(
    domain_list: List[str],  # List of domains to search
    output_path: str = None,  # if included, output results to JSON
    verbose: bool = False,  # Verbose mode (more printing!)
    all_domains: bool = False,  # Includes domains that dont have cdn's in the output
    interactive: bool = False,  # Includes a progress bar (normally used for command line)
    double_in: bool = False,  #D ouble the number of tries on a domain to increase accuracy
    threads: int = THREADS,  # Number of threads to use
    timeout: int = TIMEOUT,  # How long to wait on a domain
    user_agent: str = USER_AGENT,  # User Agent to use
)

Example

import findcdn
import json

domains = ['google.com', 'cisa.gov', 'censys.io', 'yahoo.com', 'pbs.org', 'github.com']
resp_json = findcdn.main(domains, output_path="output.json", double_in=True, threads=23)

dumped_json = json.loads(resp_json)

for domain in dumped_json['domains']:
    print(f"{domain} has CDNs:\n {dumped_json['domains'][domain]['cdns']}")

Inner-Component Usage

If you wish to use inner libraries individually, the following will describe how to use each one:

findcdn

Method to Use: main() --> findcdn.main()

Parameters:

Required:

  • domain_list: List[str]

Optional:

  • output_path: str 
  • verbose: bool
  • all_domains: bool
  • interactive: bool
  • double_in: bool
  • threads: int
  • timeout: int
  • user_agent: str

Returns:

  • JSON string of domains with CDNs (str)

cdnEngine

Method to Use: run_checks() --> findcdn.cdnEngine.run_checks()

Parameters:

Required:

  • domains: List[str]
  • threads: int
  • timeout: int
  • user_agent: str

Optional:

  • interactive: bool
  • verbose: bool
  • double: bool

Returns:

  • Tuple[List[detectCDN.Domain], int, int] # List of domains, count of jobs

detectCDN

File to Use: cdn_check.py
Parameters For Classes:

  • Domain Required:

    • url: str
      
  • cdnCheck No parameters required

Usage:

After defining a cdnCheck object, pass the Domain object like so:

d = detectCDN.Domain("domain.com")
c = detectCDN.cdnCheck()

# Checks are done and maintained in domain object
c.all_checks(d)