Skip to content

Instantly share code, notes, and snippets.

@darron1217
Last active June 4, 2024 04:16
Show Gist options
  • Save darron1217/5260adbc87392fc6a1b73579d4945801 to your computer and use it in GitHub Desktop.
Save darron1217/5260adbc87392fc6a1b73579d4945801 to your computer and use it in GitHub Desktop.
beacon peer public ip filter
#!/bin/bash
JSON_FILE="beacon-peers.json"
is_private_ip() {
local ip=$1
if [[ $ip =~ ^10\..* ]] || \
[[ $ip =~ ^172\.(1[6-9]|2[0-9]|3[01])\..* ]] || \
[[ $ip =~ ^192\.168\..* ]]; then
return 0
else
return 1
fi
}
jq -r '
.data[] |
select(
(.last_seen_p2p_address | test("^/ip4/(10\\.|172\\.(1[6-9]|2[0-9]|3[01])\\.|192\\.168\\.)") | not)
) |
"\(.last_seen_p2p_address)/p2p/\(.peer_id)"
' $JSON_FILE | paste -sd "," -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment