Initial commit

Includes IPv4 and IPv6 support, and a CLI for generating IpRanges from ip2location DB1 CSV files.
This commit is contained in:
2025-03-11 21:16:25 -06:00
commit ebb7bbdf47
17 changed files with 789 additions and 0 deletions
Executable
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# This script takes a list of arguments for each database to download
# and extract. Keep in mind that IP2LOCATION has a rate limit.
cd "$(dirname "$0")"
# This script requires `secret.sh` to define the following environment variables:
# - IP2LOCATION_TOKEN
. secret.sh
BASE_URL="https://www.ip2location.com/download/?token=$IP2LOCATION_TOKEN&file="
for CODE in "$@"
do
if [[ $CODE == *IPV6 ]]
then
DB="${CODE::${#CODE}-4}"
ver="V6"
else
DB="$CODE"
ver="V4"
fi
dbx="${DB::${#DB}-7}"
ext="${DB:(-3)}"
curl -L "$BASE_URL$CODE" > tmp.zip
unzip -p tmp.zip "*.$ext" > "$dbx-LITE-$ver.$ext"
rm tmp.zip
done