From 7605e699d0826343f8bd0900f3288775d0afeedc Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Wed, 16 Oct 2024 17:06:01 +0000 Subject: [PATCH] Initial commit --- collect.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 collect.sh diff --git a/collect.sh b/collect.sh new file mode 100755 index 0000000..ba975d8 --- /dev/null +++ b/collect.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +IPV4_LIST=./ips-v4 +IPV6_LIST=./ips-v6 +ASLIST="" + +# Truncate +true > "$IPV4_LIST" +true > "$IPV6_LIST" + +ASLIST="$ASLIST 32934" # Facebook (Meta) +ASLIST="$ASLIST 16509" # Amazon (AWS) +ASLIST="$ASLIST 15169" # Google +ASLIST="$ASLIST 136907" # Huawei Cloud + +for ASN in $ASLIST; do + LIST="$(\ + curl -L \ + 'https://stat.ripe.net/data/announced-prefixes/data.json?resource=AS'"$ASN" | \ + jq -r '.data.prefixes[].prefix')" + + # Cheap trick to separate IPs + echo "$LIST" | grep '\.' >> "$IPV4_LIST" + echo "$LIST" | grep -v '\.' >> "$IPV6_LIST" +done + +# Sort from least specific to most +TMPFILE="$(mktemp -p /tmp)" +< "$IPV4_LIST" sort | uniq | sed 's;/;,;g' | xsv sort -s 2 -n | sed 's;,;/;g' > "$TMPFILE" +cp "$TMPFILE" "$IPV4_LIST" + +< "$IPV6_LIST" sort | uniq | sed 's;/;,;g' | xsv sort -s 2 -n | sed 's;,;/;g' > "$TMPFILE" +cp "$TMPFILE" "$IPV6_LIST" +rm -v "$TMPFILE"