Add script to determine node client versions across the network.

Co-authored-by: KPrasch <kieranprasch@gmail.com>
pull/3554/head
derekpierre 2024-08-13 10:32:15 -04:00
parent 68306d9b5e
commit d4890e419f
No known key found for this signature in database
1 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,49 @@
import asyncio
from collections import Counter
from contextlib import suppress
import aiohttp
import requests
TIMEOUT = 5
template = "https://{host}/status?json=true"
requests.packages.urllib3.disable_warnings()
async def fetch(session, url):
with suppress(Exception):
async with session.get(url, ssl=False, timeout=TIMEOUT) as response:
response = await response.json()
return response["version"]
return "unknown"
async def main():
url = template.format(host="mainnet.nucypher.network:9151")
async with aiohttp.ClientSession() as session:
async with session.get(url, ssl=False, timeout=TIMEOUT) as response:
status_data = await response.json()
nodes = status_data.get("known_nodes", [])
total_nodes = len(nodes)
print(f"Number of nodes: {total_nodes}")
tasks = set()
for node in nodes:
url = template.format(host=node["rest_url"])
tasks.add(fetch(session, url))
results = Counter()
for task in asyncio.as_completed(tasks):
if task:
result = await task
results[result] += 1
items = sorted(results.items(), key=lambda result: result[1], reverse=True)
for version, count in items:
print(f"Version {version}: {count} nodes ({count*100/total_nodes:.1f}%)")
asyncio.run(main())