Created
May 19, 2021 22:24
-
-
Save jaapmarcus/2d894af99297437ef90d192a8dacf4a3 to your computer and use it in GitHub Desktop.
IP set example
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 | |
BEL=( | |
"http://ipverse.net/ipblocks/data/countries/be.zone" | |
"http://ipverse.net/ipblocks/data/countries/nl.zone" | |
"http://ipverse.net/ipblocks/data/countries/lu.zone" | |
) | |
IP_BEL_TMP=$(mktemp) | |
for i in "${BEL[@]}"; do | |
IP_TMP=$(mktemp) | |
(( HTTP_RC=$(curl -L --connect-timeout 10 --max-time 10 -o "$IP_TMP" -s -w "%{http_code}" "$i") )) | |
if (( HTTP_RC == 200 || HTTP_RC == 302 || HTTP_RC == 0 )); then # "0" because file:/// returns 000 | |
command grep -Po '^(?:\d{1,3}\.){3}\d{1,3}(?:/\d{1,2})?' "$IP_TMP" | sed -r 's/^0*([0-9]+)\.0*([0-9]+)\.0*([0-9]+)\.0*([0-9]+)$/\1.\2.\3.\4/' >> "$IP_BEL_TMP" | |
elif (( HTTP_RC == 503 )); then | |
echo >&2 -e "\\nUnavailable (${HTTP_RC}): $i" | |
else | |
echo >&2 -e "\\nWarning: curl returned HTTP response code $HTTP_RC for URL $i" | |
fi | |
rm -f "$IP_TMP" | |
done | |
sed -r -e '/^(0\.0\.0\.0|10\.|127\.|172\.1[6-9]\.|172\.2[0-9]\.|172\.3[0-1]\.|192\.168\.|22[4-9]\.|23[0-9]\.)/d' "$IP_BEL_TMP"|sort -n|sort -mu | |
rm -f "$IP_BEL_TMP" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment