利用Python与Shodan API编写的搜索工具
代码相对简单,根据Shodan API提供的文档示例就可以实现,需要事先注册号账户,并得到相应的API Key
import shodan import sys import termcolor class ShodanSearch: def __init__(self) -> None: shodan_api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' #替换成相应的Shodan API Key self.api = shodan.Shodan(shodan_api_key) self.banner() def banner(self): banner = """ ****************************************************************** ****************************************************************** {} ****************************************************************** ****************************************************************** """.format(termcolor.colored("Shodan Search Tool by Jason Wong V1.0",'blue')) print(banner) def run(self): try: while True: product = input("Enter the product to search: ") if product == 'q': break result = self.api.search(product) print("Reuslts found: {}".format(result['total'])) for res in result['matches']: print("IP: {}".format(res['ip_str'])) print(res['data']) except Exception as e: print(e) sys.exit() if __name__ == "__main__": shodan = ShodanSearch() shodan.run()
运行效果示意图如下:
STRIVE FOR PROGRESS,NOT FOR PERFECTION