Skip to content

Instantly share code, notes, and snippets.

@atcasanova
Created February 14, 2016 18:47
Show Gist options
  • Save atcasanova/09fba3fe183863297567 to your computer and use it in GitHub Desktop.
Save atcasanova/09fba3fe183863297567 to your computer and use it in GitHub Desktop.
Script simples para testar limite de conexão
#!/bin/bash
trap 'stats' SIGINT SIGTERM
(( $# != 4 )) && (( $# != 2 )) && { echo "($#) uso: $0 -u <url de ataque> { -t <timeout de cada acesso (default 3)> }"; exit 3; }
while getopts "u:t:" option
do
case "$option" in
u) url="$OPTARG";;
t) timeout="$OPTARG";;
esac
done
grep -q "https://" <<< "$url" && https="--no-check-certificate"
RED='\033[0;31m'
NC='\033[0m'
GREEN='\033[0;32m'
i=0;
start=$(date +%s)
date
last=1
stats(){
(( $i < 1 )) && exit 1;
echo ""
date
echo "================================================================"
echo "$i tentativas de conexão a $url"
echo "${passou:-0} tentativas com sucesso"
echo "${naopassou:-0} tentativas bloqueadas"
echo "Primeiro bloqueio: ${primeiroblock:-nenhum}"
echo "Última conexão com sucesso: ${lastok:-nenhuma}"
echo "${block:-0} bloqueios até a interrupção do script"
echo "================================================================"
kill -9 $$;
}
while true;
do
wget --timeout=${timeout:-3} -qO/dev/null $https --tries=1 $url && {
let ok++;
nok=0
let passou++
last=1
let i++
lastok=$i
echo -e "$GREEN$i: (+$(($(date +%s) - $start))s) (${passou:-0} OK ($ok)) (${naopassou:-0} FAIL ($nok)) ${block:-0} bloqueios$NC"
} || {
(( $last == 1 )) && let block++
last=0
let nok++;
ok=0
let naopassou++
let i++
(( ${flag:-0} == 0 )) && { primeiroblock=$i; flag=1; }
echo -e "$RED$i: (+$(($(date +%s) - $start))s) (${passou:-0} OK ($ok)) (${naopassou:-0} FAIL ($nok)) ${block:-0} bloqueios$NC"
}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment