theHarvester/discovery/shodan/cli/helpers.py
laramies 973220d3d1 Release 3.0
Added Port scanning, Subdomain takeover, Fixed Shodan, improved Dns bruteforce and added SQLite support to store the results.
2018-08-08 21:34:10 +02:00

24 lines
674 B
Python

'''
Helper methods to create your own CLI commands.
'''
import click
import os
from .settings import SHODAN_CONFIG_DIR
def get_api_key():
'''Returns the API key of the current logged-in user.'''
shodan_dir = os.path.expanduser(SHODAN_CONFIG_DIR)
keyfile = shodan_dir + '/api_key'
# If the file doesn't yet exist let the user know that they need to
# initialize the shodan cli
if not os.path.exists(keyfile):
raise click.ClickException('Please run "shodan init <api key>" before using this command')
# Make sure it is a read-only file
os.chmod(keyfile, 0o600)
with open(keyfile, 'r') as fin:
return fin.read().strip()