Skip to content

Instantly share code, notes, and snippets.

@dlanileonardo
Last active September 3, 2015 23:16
Show Gist options
  • Save dlanileonardo/c32e6d16b31a22c5367e to your computer and use it in GitHub Desktop.
Save dlanileonardo/c32e6d16b31a22c5367e to your computer and use it in GitHub Desktop.
Cria um redirecionamento de porta para o Azk.
#!/bin/bash
INPUT_PORT=8000
# Usage info
show_help() {
cat << EOF
Uso: ${0##*/} [-arl]
Redirecionamento da porta $INPUT_PORT para um Serviço Azk.
-h display this help and exit
-a Add rule for Azk
-r Remove fule for Azk
-l List rules NAT that foward to Azk
EOF
}
OPTIND=1 # Reset is necessary if getopts was used previously in the script. It is a good idea to make this local in a function.
while getopts "harl" opt; do
case "$opt" in
h)
show_help
exit 0
;;
a)
INTERNAL_IP=`/sbin/ifconfig wlan0|grep inet|head -1|sed 's/\:/ /'|awk '{print $3}'`
AZK_IP=172.17.42.1
echo "Qual a porta alvo do Azk?"
read AZK_PORTA_ALVO
sudo iptables -t nat -A PREROUTING -p tcp -d $INTERNAL_IP --dport $INPUT_PORT -j DNAT --to $AZK_IP:$AZK_PORTA_ALVO
echo "Azk Escutando na porta $INPUT_PORT"
exit 1
;;
r)
echo "Selecione o numer da regra a excluir:"
sudo iptables -L -t nat --line-numbers | grep "to:172.17.42.1:"
echo "--------------------------------------------------------"
echo "Digite o número da regra a excluir:"
read IPTABLES_LINE_NUMBER
sudo iptables -t nat -D PREROUTING $IPTABLES_LINE_NUMBER
echo "Regra removida com sucesso!"
exit 1
;;
l)
echo "Lista de regras que apontam pro Azk:"
sudo iptables -L -t nat --line-numbers | grep "to:172.17.42.1:"
exit 1
;;
'?')
show_help >&2
exit 1
;;
esac
done
shift "$((OPTIND-1))" # Shift off the options and optional --.
show_help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment