2 from hashlib import sha256
7 with open("config.json") as f:
8 config = json.loads(f.read())
13 "activitypub-troll.cf",
20 "user-agent": config["useragent"]
24 def get_hash(domain: str) -> str:
25 return sha256(domain.encode("utf-8")).hexdigest()
28 def get_peers(domain: str) -> str:
30 res = get(f"https://{domain}/api/v1/instance/peers", headers=headers, timeout=5)
35 peerlist = get_peers(domain)
37 def get_type(instdomain: str) -> str:
39 res = get(f"https://{instdomain}/nodeinfo/2.1.json", headers=headers, timeout=5)
40 if res.status_code == 404:
41 res = get(f"https://{instdomain}/nodeinfo/2.0", headers=headers, timeout=5)
42 if res.status_code == 404:
43 res = get(f"https://{instdomain}/nodeinfo/2.0.json", headers=headers, timeout=5)
44 if res.ok and "text/html" in res.headers["content-type"]:
45 res = get(f"https://{instdomain}/nodeinfo/2.1", headers=headers, timeout=5)
47 if res.json()["software"]["name"] in ["akkoma", "rebased"]:
49 elif res.json()["software"]["name"] in ["hometown", "ecko"]:
51 elif res.json()["software"]["name"] in ["calckey", "groundpolis", "foundkey", "cherrypick"]:
54 return res.json()["software"]["name"]
55 elif res.status_code == 404:
56 res = get(f"https://{instdomain}/api/v1/instance", headers=headers, timeout=5)
63 conn = sqlite3.connect("blocks.db")
67 "select domain from instances where 1"
70 for instance in peerlist:
71 instance = instance.lower()
74 for domain in blacklist:
75 if domain in instance:
84 "select domain from instances where domain = ?", (instance,)
86 if c.fetchone() == None:
88 "insert into instances select ?, ?, ?",
89 (instance, get_hash(instance), get_type(instance)),
92 except Exception as e:
93 print("error:", e, instance)