blockcheck: verbose output in ip block tests

This commit is contained in:
bol-van 2024-06-22 15:38:22 +03:00
parent 04e8106b98
commit b23b98a14b

View File

@ -575,12 +575,18 @@ curl_test_http()
# $1 - ip version : 4/6 # $1 - ip version : 4/6
# $2 - domain name # $2 - domain name
# $3 - subst ip # $3 - subst ip
# $4 - "detail" - detail info
local code loc local code loc
curl_probe $1 $2 $HTTP_PORT "$3" -SsD "$HDRTEMP" -A "$USER_AGENT" --max-time $CURL_MAX_TIME $CURL_OPT "http://$2" -o /dev/null 2>&1 || { curl_probe $1 $2 $HTTP_PORT "$3" -SsD "$HDRTEMP" -A "$USER_AGENT" --max-time $CURL_MAX_TIME $CURL_OPT "http://$2" -o /dev/null 2>&1 || {
code=$? code=$?
rm -f "$HDRTEMP" rm -f "$HDRTEMP"
return $code return $code
} }
if [ "$4" = "detail" ] ; then
head -n 1 "$HDRTEMP"
grep "^[lL]ocation:" "$HDRTEMP"
else
code=$(hdrfile_http_code "$HDRTEMP") code=$(hdrfile_http_code "$HDRTEMP")
[ "$code" = 301 -o "$code" = 302 -o "$code" = 307 -o "$code" = 308 ] && { [ "$code" = 301 -o "$code" = 302 -o "$code" = 307 -o "$code" = 308 ] && {
loc=$(hdrfile_location "$HDRTEMP") loc=$(hdrfile_location "$HDRTEMP")
@ -591,6 +597,7 @@ curl_test_http()
return 254 return 254
} }
} }
fi
rm -f "$HDRTEMP" rm -f "$HDRTEMP"
[ "$code" = 400 ] && { [ "$code" = 400 ] && {
# this can often happen if the server receives fake packets it should not receive # this can often happen if the server receives fake packets it should not receive
@ -820,18 +827,20 @@ curl_test()
# $1 - test function # $1 - test function
# $2 - domain # $2 - domain
# $3 - subst ip # $3 - subst ip
# $4 - param of test function
local code=0 n=0 local code=0 n=0
while [ $n -lt $REPEATS ]; do while [ $n -lt $REPEATS ]; do
n=$(($n+1)) n=$(($n+1))
[ $REPEATS -gt 1 ] && printf "[attempt $n] " [ $REPEATS -gt 1 ] && printf "[attempt $n] "
if $1 "$IPV" $2 $3 ; then if $1 "$IPV" $2 $3 "$4" ; then
[ $REPEATS -gt 1 ] && echo 'AVAILABLE' [ $REPEATS -gt 1 ] && echo 'AVAILABLE'
else else
code=$? code=$?
[ "$SCANLEVEL" = quick ] && break [ "$SCANLEVEL" = quick ] && break
fi fi
done done
[ "$4" = detail ] || {
if [ $code = 254 ]; then if [ $code = 254 ]; then
echo "UNAVAILABLE" echo "UNAVAILABLE"
elif [ $code = 0 ]; then elif [ $code = 0 ]; then
@ -839,6 +848,7 @@ curl_test()
else else
echo "UNAVAILABLE code=$code" echo "UNAVAILABLE code=$code"
fi fi
}
return $code return $code
} }
ws_curl_test() ws_curl_test()
@ -1236,7 +1246,7 @@ check_dpi_ip_block()
echo echo
echo "- IP block tests (requires manual interpretation)" echo "- IP block tests (requires manual interpretation)"
echo "testing $UNBLOCKED_DOM on it's original ip" echo "> testing $UNBLOCKED_DOM on it's original ip"
if curl_test $1 $UNBLOCKED_DOM; then if curl_test $1 $UNBLOCKED_DOM; then
unblocked_ip=$(mdig_resolve $IPV $UNBLOCKED_DOM) unblocked_ip=$(mdig_resolve $IPV $UNBLOCKED_DOM)
[ -n "$unblocked_ip" ] || { [ -n "$unblocked_ip" ] || {
@ -1244,13 +1254,13 @@ check_dpi_ip_block()
return 1 return 1
} }
echo "testing $blocked_dom on $unblocked_ip ($UNBLOCKED_DOM)" echo "> testing $blocked_dom on $unblocked_ip ($UNBLOCKED_DOM)"
curl_test $1 $blocked_dom $unblocked_ip curl_test $1 $blocked_dom $unblocked_ip detail
blocked_ips=$(mdig_resolve_all $IPV $blocked_dom) blocked_ips=$(mdig_resolve_all $IPV $blocked_dom)
for blocked_ip in $blocked_ips; do for blocked_ip in $blocked_ips; do
echo "testing $UNBLOCKED_DOM on $blocked_ip ($blocked_dom)" echo "> testing $UNBLOCKED_DOM on $blocked_ip ($blocked_dom)"
curl_test $1 $UNBLOCKED_DOM $blocked_ip curl_test $1 $UNBLOCKED_DOM $blocked_ip detail
done done
else else
echo $UNBLOCKED_DOM is not available. skipping this test. echo $UNBLOCKED_DOM is not available. skipping this test.