Post #2877899
2026-04-21 16:30 UTC
@gayint@infosec.exchange so in the asnsToPrefixes page you say you'd appreciate hearing about what people have done with the script, so have some bash:
for line in "${asn_list[@]}";do
res_json=$(curl -fsSL "https://stat.ripe.net/data/announced-prefixes/data.json?resource=AS${line}")
if [ ! -z "${res_json}" ];then
# convert json into iptables rules.v4 lines
echo "${res_json}" | jq -r '.data.prefixes[].prefix' | grep -v ':' | sort -g | sed "s/^/-A INPUT -s /;s/$/ -m comment --comment \"drop AS${line}\" -j DROP/"
else
echo "Error: Unable to retrieve json for ${line}"
fi
done
hopefully this is useful to someone, the sed expression could be modified to output other blocklist formats if needed, and rules.v6 output could be easily added as well
Replies (0)
No replies.