-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_active_peers.sh
48 lines (41 loc) · 1.03 KB
/
get_active_peers.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
help()
{
echo "The easiest and fastest way to get the active peers list."
echo
echo "Syntax: bash <(curl -Lfs https://raw.githubusercontent.com/EZStaking/ez_utilities/main/get_active_peers.sh) [OPTIONS] [RPC_NODE]"
echo "Syntax: ./get_active_peers.sh [OPTIONS] [RPC_NODE]"
echo
echo "options:"
echo -e " -h\t Print this help and exit"
}
while getopts ":h" option; do
case $option in
h)
help
exit;;
\?)
echo "Error: Invalid option"
exit;;
esac
done
shift $((OPTIND-1))
if [[ -z $1 ]]; then
help
exit
fi
RPC_NODE=${1/tcp/http}
NET_INFO=$(curl -s $RPC_NODE/net_info)
# Toml Peers List
PEERS=$(echo "${NET_INFO}" |
jq -r '.result.peers[] |
"\(.node_info.id)@\(.remote_ip):\(.node_info.listen_addr | (split(":")[-1]) |select(. != null))" |
select(. | match("([0-9]{1,3}[\\.]){3}[0-9]{1,3}"))' |
paste -sd,
)
# Nb. of Peers
N_PEERS=$(echo "${NET_INFO}" | jq -r '.result.n_peers')
echo "Peers:"
echo "${PEERS}"
echo ""
echo "Nb. of Peers: ${N_PEERS}"