#!/usr/bin/env bash ########################################################################### ## Copyright (C) Wizardry and Steamworks 2020 - License: GNU GPLv3 ## ########################################################################### # Downloads the IP blocks for selected countries and creates IP sets. ## ########################################################################### ########################################################################### ## CONFIGURATION ## ########################################################################### # Generate IP sets for the following country codes. COUNTRY_CODES=( sv ) ########################################################################### ## INTERNALS ## ########################################################################### JSON_BASH_PARSER=$(cat </dev/null >/dev/null` if [ $? = 1 ]; then ipset create $SET_NAME hash:net family $FAMILY fi ipset flush $SET_NAME done curl -s -o - 'https://stat.ripe.net/data/country-resource-list/data.json?v4_format=prefix;resource='$COUNTRY | \ json | \ while read LINE; do K=$(echo $LINE | awk -F'=' '{ print $1 }') V=$(echo $LINE | awk -F'=' '{ print $2 }') if [ "$K" = "status" ] && [ "$V" != "ok" ]; then for FAMILY in inet inet6; do ipset destroy $COUNTRY"-"$FAMILY 2>/dev/null >/dev/null done continue fi case $( echo "$K" | cut -c 1-19 ) in "data.resources.ipv4") ipset add $COUNTRY"-inet" $V ;; "data.resources.ipv6") ipset add $COUNTRY"-inet6" $V ;; esac done done