Skip to content

Instantly share code, notes, and snippets.

@cheeseonamonkey
Created January 2, 2026 05:31
Show Gist options
  • Select an option

  • Save cheeseonamonkey/db600d0d3be41388941bcaaa3e1631c0 to your computer and use it in GitHub Desktop.

Select an option

Save cheeseonamonkey/db600d0d3be41388941bcaaa3e1631c0 to your computer and use it in GitHub Desktop.
netcheck() {
emulate -L zsh
setopt local_options no_monitor no_notify
local R=$'\e[0m' B=$'\e[1m' G=$'\e[32m' E=$'\e[31m' D=$'\e[90m'
local OK="${B}${G}✓${R}" NO="${B}${E}✗${R}" WAIT="${D}…${R}"
local host=google.com url=http://connectivitycheck.gstatic.com/generate_204
local dns=$WAIT http=$WAIT dp hp dr hr
draw(){ print -nr -- $'\r\e[2K'"DNS [$dns] | HTTP [$http]"; }
{ (command -v dig >/dev/null && dig +time=1 +tries=1 $host || getent hosts $host) >/dev/null 2>&1 } & dp=$!
{ curl -fsS --max-time 2 $url >/dev/null 2>&1 } & hp=$!
draw
wait $dp; dr=$?; dns=$([ $dr -eq 0 ] && echo $OK || echo $NO); draw
wait $hp; hr=$?; http=$([ $hr -eq 0 ] && echo $OK || echo $NO); draw; echo
(( dr==0 && hr==0 ))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment