Last active
June 4, 2024 04:16
-
-
Save darron1217/5260adbc87392fc6a1b73579d4945801 to your computer and use it in GitHub Desktop.
beacon peer public ip filter
This file contains 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 | |
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