Created
August 9, 2018 13:26
-
-
Save kgersen/024d6dfb49c328545342dde92aaf354e to your computer and use it in GitHub Desktop.
RIPE alloclist to database conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# convert RIPE allocation list to database friendly format | |
# (c) kgersen 2018 for https://lafibre.info | |
# tab (\t) is used as separator in output | |
# output | |
# country ispcode ispname date 4|6 block block_size | |
# optionnal argument: country code to match | |
url="https://ftp.ripe.net/ripe/stats/membership/alloclist.txt" | |
alloc2db() | |
{ | |
skip="no" | |
while read line; do | |
case $line in | |
([a-z]*.[a-z0-9]*) | |
isp=$line | |
country=${isp%%.*} | |
if [ ! -z "$1" ]; then if [ ! "$country" == "$1" ]; then skip=""; continue; fi; fi | |
skip="no" | |
ispcode=${isp#*.} | |
read line | |
ispname=$line | |
ispname="${ispname//\"}";; | |
("") | |
;; | |
(*) | |
if [ -z "$skip" ]; then continue; fi | |
read -r date block trash <<<"$line" | |
#date="$(date --date="$date" "+%Y/%m/%d")" | |
date=${date:0:4}/${date:4:2}/${date:6:2} | |
size=${block#*/} | |
if [[ $block = *"::"* ]]; then | |
ipv="6" | |
block_size=$[2**(64-$size)] | |
else | |
ipv="4" | |
block_size=$[2**(32-$size)] | |
fi | |
echo -e $country$'\t'$ispcode$'\t'$ispname$'\t'$date$'\t'$ipv$'\t'$block$'\t'$block_size;; | |
esac | |
done | |
} | |
curl -s "$url" | alloc2db $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment