MCPcopy Create free account
hub / github.com/EASY233/Finger / Fofa

Class Fofa

api/fofa.py:14–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13
14class Fofa:
15 def __init__(self):
16 self.email = Fofa_email
17 self.key = Fofa_key
18 self.size = Fofa_Size
19 self.headers = {
20 "User-Agent": random.choice(user_agents)
21 }
22 if self.check():
23 if Ips.ip:
24 for ip in Ips.ip:
25 ip = "ip={}".format(ip)
26 self.run(ip)
27 else:
28 try:
29 logging.info("[FOFA Example]domain=example.com\n")
30 while 1:
31 keyword = input("请输入查询关键词:").strip()
32 size = input("请输入查询的数量(默认100):").strip()
33 self.size = int(size) if size else 100
34 if keyword == "":
35 logging.error("\n关键字不能为空!")
36 else:
37 break
38 self.run(keyword)
39 except KeyboardInterrupt:
40 logging.error("\n用户取消输入!直接退出。")
41 exit(0)
42 else:
43 logging.error("fofa api不可用,请检查配置是否正确!")
44
45 def run(self,keyword):
46 logging.info("正在调用fofa进行收集资产。。。。")
47 logging.info("查询关键词为:{0},查询数量为:{1}".format(keyword,self.size))
48 keyword = quote(str(base64.b64encode(keyword.encode()), encoding='utf-8'))
49 url = "https://fofa.info/api/v1/search/all?email={0}&key={1}&qbase64={2}&full=false&fields=protocol,host&size={3}".format(
50 self.email, self.key, keyword, self.size)
51 try:
52 response = requests.get(url,timeout=10,headers = self.headers )
53 datas = json.loads(response.text)
54 if "results" in datas.keys():
55 for data in datas["results"]:
56 _url = ""
57 if "http" in data[1] or "https" in data[1]:
58 _url = data[1]
59 elif "http" == data[0] or "https" == data[0]:
60 _url = "{0}://{1}".format(data[0], data[1])
61 elif "" == data[0]:
62 _url = "{0}://{1}".format("http", data[1])
63 if _url:
64 logging.info(_url)
65 Urls.url.append(_url)
66 except requests.exceptions.ReadTimeout:
67 logging.error("请求超时")
68 except requests.exceptions.ConnectionError:
69 logging.error("网络超时")
70 except json.decoder.JSONDecodeError:
71 logging.error("获取失败,请重试")

Callers 2

api_dataMethod · 0.90
get_ipMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected