Skip to content

Void shodan library  #49

@Ekultek

Description

@Ekultek

Would it be an issue to create your own shodan library for this, something along the lines of:

import json
import time
import threading
import base64

import requests

import lib.settings
import lib.output


def get_token(encoded):
    encoded = encoded.strip()
    token, n = encoded.split(":")
    for _ in range(int(n)):
        token = base64.b64decode(token)
    return token


def gather_hosts(query):
    discovered = set()

    try:
        animation_text = "gathering hosts relevant to query {}...".format(query)
        t = threading.Thread(target=lib.settings.animation, args=(animation_text,))
        t.daemon = True
        t.start()

        token = get_token(open(lib.settings.TOKEN_PATH).read())
        req = requests.get(lib.settings.SHODAN_API_LINK.format(key=token, query=query))
        data = json.loads(req.content)
        for match in data["matches"]:
            discovered.add(match["ip_str"])
        file_path = "{}/hosts.lst".format(lib.settings.GATHERED_HOSTS_PATH)
        lib.settings.write_to_file(discovered, file_path)
        output_text = "done, successfully gathered {} hosts".format(len(discovered))
        padding_needed = len(animation_text) - len(output_text)
        lib.output.info(output_text + "{}".format(" " * padding_needed))
        lib.settings.STOP_ANIMATION = True
        return file_path
    except Exception as e:
        lib.output.error("caught exception '{}' while gathering hosts".format(str(e)))
        lib.settings.shutdown()


def view_gathered_hosts(host_file):
    with open(host_file) as hosts:
        for i, host in enumerate(hosts, start=1):
            lib.output.info("[{}] {}".format(i, host.strip()))
    return

That should grab at least 100 IP addresses from shodan

Metadata

Metadata

Assignees

Labels

APIAPI connection requestedenhancementNew feature or requestneed-to-implementDone, just needs to be implemented

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions