-
Notifications
You must be signed in to change notification settings - Fork 1
/
peer_matching.py
36 lines (25 loc) · 997 Bytes
/
peer_matching.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
import requests
import json
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--node', type=str, default='[::1]:7076')
args = parser.parse_args()
def node(data):
return requests.post('http://'+args.node, json=data).json()
get_peers = node({"action":"peers", "peer_details":"true"})
telemetry = node({"action":"node_telemetry", "raw":"true"})
all_peers = get_peers["peers"]
other_peers = {k: v["protocol_version"] for k,v in all_peers.items() if v["protocol_version"] != '18'}
peers = {k: v["protocol_version"] for k,v in all_peers.items() if v["protocol_version"] == '18'}
match = []
unmatch = []
for peer in telemetry["metrics"]:
ip = '['+peer["address"]+']:'+peer["port"]
if ip in peers:
network = peers.pop(ip)
match.append(ip)
else:
unmatch.append(ip)
print("{} Match\n{}\n\n\n{} Unmatch\n{}\n\n".format(len(match), match, len(unmatch), unmatch))
print("{} Unknown\n{}".format(len(peers), peers))