Created
December 3, 2018 17:04
-
-
Save nexus166/3cd408ea95c2eae32f33530462f880b5 to your computer and use it in GitHub Desktop.
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/sh | |
COUNTRY="$(echo "$1" | tr '[:upper:]' '[:lower:]')" | |
if [ -z "$COUNTRY" ]; then printf "\\n\\tNO COUNTRY CODE SPECIFIED\\n\\n" && exit 1; fi | |
IPSET_SET="${COUNTRY}-subnets" | |
IPSET="$(command -v ipset || exit 1)" | |
printf "\\n\\tPREPARING IPSET SET\\t\\t\\t[%s]" "$IPSET_SET" && \ | |
"$IPSET" flush "$IPSET_SET" || "$IPSET" create "$IPSET_SET" hash:net && \ | |
printf "\\n\\tDOWNLOADING AND IMPORTING SUBNETS.." && \ | |
curl -s -o- "http://www.ipdeny.com/ipblocks/data/countries/$COUNTRY.zone" | \ | |
grep -Eo '[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+/[0-9]+' | \ | |
while read -r IP; do "$IPSET" add "$IPSET_SET" "$IP"; done && printf "\\tOK" | |
printf "\\n\\tTOTAL SUBNETS IN SET %s:\\t%s\\n\\n" "$IPSET_SET" "$(echo $(($($IPSET list "$IPSET_SET" | wc -l) - 8)))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment