You've already forked ipfilter
ebb7bbdf47
Includes IPv4 and IPv6 support, and a CLI for generating IpRanges from ip2location DB1 CSV files.
32 lines
647 B
Bash
Executable File
32 lines
647 B
Bash
Executable File
#!/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
|