Initial commit

This commit is contained in:
Alex D. 2024-10-16 17:06:01 +00:00
commit 7605e699d0
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
1 changed files with 34 additions and 0 deletions

34
collect.sh Executable file
View File

@ -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"