Skip to content

Instantly share code, notes, and snippets.

@sistematico
Last active August 19, 2016 23:30
Show Gist options
  • Select an option

  • Save sistematico/f51b16b16ce3dcbec9cf38d2e9657a25 to your computer and use it in GitHub Desktop.

Select an option

Save sistematico/f51b16b16ce3dcbec9cf38d2e9657a25 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Sintaxe para encontrar os IPS.
# host -t a DOMINIO
# whois -h whois.radb.net [IP] | grep origin
# whois -h whois.radb.net -- -i origin -T route AS32934 | grep route:
#
# Script por Lucas Saliés Brum, a.k.a. sistematico, <lucas AT archlinux DOT com DOT br>.
# Criado em 03/08/16
# Alterado em 03/08/16
rm -f /tmp/as.txt
rm -f /tmp/ips.txt
IP_PRINC=$(host -t a $2 | cut -d ' ' -f4)
ping -c 1 $2 2>/dev/null 1>/dev/null
if [ "$?" != 0 ]
then
echo "Domínio inválido."
exit 1
fi
if [ ! $(which ufw) ]
then
echo "UFW não encontrado."
exit 1
fi
whois -h whois.radb.net $IP_PRINC | grep origin: | cut -d ':' -f2 | sed -e 's/ //g' > /tmp/as.txt
while read as; do
#echo "AS: ${as}"
whois -h whois.radb.net -- -i origin -T route $as | grep route: | cut -d ':' -f2 | sed -e 's/ //g' > /tmp/ips.txt
done < /tmp/as.txt
echo $#
if [ $# -eq 2 ]
then
if [ "$1" = "--block" ]
then
while read p; do
echo "IP: $p bloqueado."
ufw deny from $p
ufw deny to $p
done < /tmp/ips.txt
elif [ "$1" = "--unblock" ]
then
while read p; do
echo "IP: $p bloqueado."
ufw delete deny from $p
ufw delete deny to $p
done < /tmp/ips.txt
else
echo "Parametros incorretos."
exit 1
fi
else
echo "Uso: $(basename $0) --block google.com"
echo "Uso: $(basename $0) --unblock google.com"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment