Last active
August 3, 2016 18:01
-
-
Save felmoltor/0fff85f77e50d4034cc3e06cc17ed67a to your computer and use it in GitHub Desktop.
Negotiate Content Scanner (RFC 2616)
This file contains 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 | |
################# | |
# CONFIG COLORS # | |
################# | |
# Text color variables | |
txtund=$(tput sgr 0 1) # Underline | |
txtbld=$(tput bold) # Bold | |
bldred=${txtbld}$(tput setaf 1) # red | |
bldblu=${txtbld}$(tput setaf 4) # blue | |
bldwht=${txtbld}$(tput setaf 7) # white | |
txtrst=$(tput sgr0) # Reset | |
info=${bldwht}*${txtrst} # Feedback | |
pass=${bldblu}*${txtrst} | |
warn=${bldred}*${txtrst} | |
ques=${bldblu}?${txtrst} | |
################ | |
if [ ! $# == 2 ] && [ ! $# == 3 ];then | |
echo "Usage: $0 <http address> <dictionary> [<N alternatives>]" | |
exit 1 | |
fi | |
nalternatives=1 | |
if [ ! -z $3 ];then | |
nalternatives=$3 | |
fi | |
# Beep with echo -ne '\007' | |
echo "Beep when more than $nalternatives alternatives is found" | |
if [ ! -r $2 ];then | |
echo "The file $2 does not exists or is not readable" | |
exit 2 | |
fi | |
for line in `cat $2`;do | |
response=$(curl -s -I --header "Accept: mierdapura/caca" --header "Connection: close" $1/$line) | |
code=$(echo $response | grep -E "HTTP/1.1 |HTTP/1.0 " | cut -f2 -d' ') | |
alternatives=$(echo $response | grep -oE "{\".*}}") | |
n=$(echo $alternatives | wc -l) | |
if [ $code == 406 ];then | |
echo -n "[$bldblu SUCCESS$txtrst ] ($code) - " | |
else | |
n=0 | |
echo -n "[$bldred FAIL $txtrst] ($code) - " | |
fi | |
echo "$1/$line: $n alternatives found" | |
if [ $code == 406 ];then | |
n=$(echo $alternatives | wc -l) | |
if [ $n -gt $nalternatives ];then | |
echo -ne '\007' | |
echo "------------------------------------" | |
echo "- $alternatives " | |
echo "------------------------------------" | |
fi | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment