Skip to content

Instantly share code, notes, and snippets.

@chew-z
Created November 21, 2016 15:05
Show Gist options
  • Select an option

  • Save chew-z/34e6dbb130970c32438cd840da9e3934 to your computer and use it in GitHub Desktop.

Select an option

Save chew-z/34e6dbb130970c32438cd840da9e3934 to your computer and use it in GitHub Desktop.
Check router connection hijacking (captive portal)
#!/usr/bin/env zsh
# adapted from Alterstep dnscrypt-proxy OSX client
try_resolution() {
exec alarmer 5 dig +tries=2 +time=3 +short github.com | egrep '^192[.]30[.]' > /dev/null 2>&1
}
try_http_query() {
exec alarmer 5 curl -L --max-redirs 5 -4 -m 5 --connect-timeout 5 -s \
http://icanhazip.com/ 2>/dev/null | \
fgrep -c '.' > /dev/null 2>&1
}
try_everything() {
try_resolution &
resolution_pid=$!
try_http_query &
http_query_pid=$!
wait $resolution_pid
resolution_ret=$?
if [ $resolution_ret != 0 ]; then
return 1
fi
wait $http_query_pid
http_query_ret=$?
[ $resolution_ret = 0 -a $http_query_ret = 0 ]
}
try_everything_with_retries() {
try_everything || try_everything
}
try_everything_with_retries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment