Skip to content

Instantly share code, notes, and snippets.

@fjahr
Last active January 28, 2023 13:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fjahr/29dafc31d5e4297dbe9ecaf540461564 to your computer and use it in GitHub Desktop.
Just a note for myself

Examples for getting a list of active peer IPs in the bitcoin network

From your own node

Get the list of IPs known to your node and save them to the file peers_ips.txt. Then count how many IPs are in the file.

$ src/bitcoin-cli getnodeaddresses 0 | jq -r '.[] | .address' > peer_ips.txt
$ wc -l peer_ips.txt

From Bitnodes

Get the list of nodes known to Bitnodes and save their IPs to the file ip_list.txt:

$ curl https://bitnodes.io/api/v1/snapshots/latest/ | jq -r '.nodes | keys[]' > ip_list.txt

Optionally filter onion addresses:

$ grep -v "onion" ip_list.txt > filtered.txt

Since the peers clearnet IPs are formatted like [_IP_]:_PORT_, to get only the IPs we need to filter the Port and brackets as well:

$ sed 's/\(.*\):.*/\1/;s/[][]//g' filtered.txt > filtered_clean.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment