Last active
March 7, 2020 15:54
-
-
Save duhow/0d8d99eb5f9045d6454171e1bbe88418 to your computer and use it in GitHub Desktop.
Create or update ipset list from FireHOL IP list
This file contains hidden or 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 | |
LIST="firehol_level1 firehol_level2" | |
URL="https://iplists.firehol.org/files/" | |
IPSET="/sbin/ipset" | |
function log(){ | |
echo "["$(date "+%Y-%m-%d %H:%M:%S")"] $@" | |
} | |
for NAME in $LIST; do | |
log "Downloading $NAME ..." | |
FILE=$(mktemp) | |
URL="https://iplists.firehol.org/files/${NAME}.netset" | |
wget -qO $FILE $URL | |
if [ ! -s "$FILE" ]; then | |
log "There was a problem downloading $NAME ." | |
exit 1 | |
fi | |
log "Adding $NAME entries to temp list..." | |
$IPSET create firehol_temp hash:net &>/dev/null | |
$IPSET flush firehol_temp &>/dev/null | |
COUNT=0 | |
while read IP; do | |
echo $IP | grep -e '^#' &>/dev/null && continue | |
$IPSET add firehol_temp $IP && COUNT=$((COUNT + 1)) | |
done < $FILE | |
$IPSET create $NAME hash:net &>/dev/null && log "Created ipset $NAME" | |
$IPSET swap firehol_temp $NAME | |
$IPSET destroy firehol_temp | |
log "$COUNT entries added for $NAME." | |
rm $FILE | |
done | |
log "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment