Skip to content

Commit 24248c9

Browse files
committed
get shodan api key from /home/josue environment variable
1 parent ab08f3a commit 24248c9

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

modules/shodan/_shodan.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from utildata.dataset_options import Option
44
from utils.shodan_search import shodan_search
55
from utils.shell_options import ShellOptions
6+
from os import getenv
67

78

89
class ShodanModule(Module):
@@ -17,6 +18,16 @@ def __init__(self, information, opts=None, default_file_name="./files/shodan.txt
1718
options.update(opts)
1819
# Constructor of the parent class
1920
super(ShodanModule, self).__init__(information, options)
21+
# Set Shodan key if exists in $HOME/.shodan/api_key and it doesn't have a global value.
22+
if not self.args["apishodan"]:
23+
try:
24+
home = getenv("HOME")
25+
shodan_key_path = home + "/.shodan/api_key"
26+
with open(shodan_key_path, "r") as f:
27+
key = f.read().strip()
28+
self.set_value(["apishodan", key])
29+
except:
30+
pass
2031

2132
# This function must be always implemented, it is called by the run option
2233
def run(self):

0 commit comments

Comments
 (0)