The ci command (connectivity info) is the primary tool for checking internet connectivity. It provides a simple true/false indication of whether both DNS and TCP connectivity are working.
Check if internet is available:
wifi-wand ciOutput:
Connected to Internet: true
Or if not connected:
Connected to Internet: false
The ci command is specifically designed for use in shell scripts where you need a simple connectivity check:
#!/bin/bash
# Check if internet is available before proceeding
if wifi-wand ci | grep -q true; then
echo "Internet is available - proceeding with upload"
# Do something that requires internet
curl https://example.com/upload --data @file.txt
else
echo "Internet is unavailable - will retry later"
# Queue the operation for later
exit 1
fiYou can also use the exit code (though the above pattern with grep is simpler):
#!/bin/bash
# Retry operation until internet is available
while ! wifi-wand ci | grep -q true; do
echo "Waiting for internet..."
sleep 10
done
echo "Internet is now available!"
# Proceed with network operations| Command | Use Case | Output | Speed |
|---|---|---|---|
ci |
Simple connectivity check | true/false | Fast |
status |
Full network summary | Multi-field status | Several seconds |
info |
Detailed network info | Complete data | Several seconds |
Use ci when you just need to know "is the internet working?". Use status when you need the complete picture of your network state.
ci checks two things:
- DNS Resolution: Can the system resolve domain names?
- TCP Connectivity: Can the system establish TCP connections?
Internet is considered available only when both are working.
#!/bin/bash
echo "Internet went down, waiting for it to come back..."
while ! wifi-wand ci | grep -q true; do
sleep 5
done
echo "Internet is back!"
mail -s "Internet restored" user@example.com < /dev/null#!/bin/bash
if wifi-wand ci | grep -q true; then
# Do something that requires internet
git push origin main
echo "Code pushed successfully"
else
echo "No internet - skipping push"
exit 1
fi#!/bin/bash
while true; do
if wifi-wand ci | grep -q true; then
echo "$(date): Internet available"
else
echo "$(date): Internet unavailable"
fi
sleep 30
doneLike the status command, ci uses intentionally long timeouts (several seconds on macOS) to avoid false positives from temporary network slowdowns. This means each check takes several seconds to complete.
If you need to check connectivity frequently, be mindful that each check will block for several seconds. Use appropriate sleep intervals between checks when polling in a loop.