Last active
June 24, 2025 13:34
-
-
Save epiccurious/82f98431ac9a2c62b0230be477cec03b to your computer and use it in GitHub Desktop.
Ban Knots peers on the bitcoin P2P network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Use Bitcoin Core to ban Knots peers | |
# NOTE 1: Start Bitcoin Core before running this script | |
# NOTE 2: To schedule runs in Linux, add this line to `crontab -e`: | |
# */5 * * * * /path/to/ban_knots_peers.sh | |
set -e | |
command -v bitcoin-cli >/dev/null || | |
{ echo "bitcoin-cli was not found" >&2 && exit 1; } | |
readonly BAN_TIME='31622400' # 366 days | |
readonly PEERS_TO_BAN="$(bitcoin-cli getpeerinfo | | |
jq -r '.[] | select(.subver | contains("Knots")) | .addr')" | |
for peer in ${PEERS_TO_BAN}; do | |
peer_ip="$(echo "${peer}" | cut -d: -f1)" | |
printf 'Banning %s' "${peer_ip}" | |
bitcoin-cli setban "${peer_ip}" add "${BAN_TIME}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment