A lightweight, low-overhead network monitoring dashboard tailored for Termux. Combines raw TCP connect and TLS handshake verification with dynamic country-code resolution, displaying a persistent in-place block progress meter on terminal. Recommended to run inside a floating Termux:Float tile.
pkg update
pkg install bash python openssl ncurses-utils coreutils
Applies an ultra-compact 190x190 window dimension with font size 10, turning Termux into an unobtrusive desktop HUD tile:
FLOAT_PREF_DIR="/data/data/com.termux.window/shared_prefs"
FLOAT_PREF_FILE="$FLOAT_PREF_DIR/com.termux.window_preferences.xml"
# Create target directory if absent
mkdir -p "$FLOAT_PREF_DIR"
# Write minimal floating layout configuration
cat << 'EOF' > "$FLOAT_PREF_FILE"
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<int name="font_size" value="10" />
<int name="window_width" value="190" />
<int name="window_height" value="190" />
</map>
EOF
# Grant proper file permissions
chmod 660 "$FLOAT_PREF_FILE"
#!/bin/bash
INTERVAL=1
TARGET_IP="1.1.1.1"
TARGET_PORT=80
REGION="--"
# Block history & status states
BLOCK_BUFFER="" # Current buffered blocks
BLOCK_COUNT=0 # Line counter (reset upon reaching 10)
CURRENT_STATE="init" # Stable state: "green", "red", "init"
FAIL_COUNT=0 # Failure counter for confirmed drops
trap "tput cnorm; exit" SIGINT SIGTERM
tput civis
clear
# Stable timeout to avoid false drops on slow handshakes
get_region() {
local loc
loc=$(python3 -c "
import urllib.request, json
try:
req = urllib.request.Request('https://api.myip.la/en?json', headers={'User-Agent': 'Mozilla/5.0'})
res = urllib.request.urlopen(req, timeout=2.5)
data = json.loads(res.read().decode())
print(data.get('location', {}).get('country_code', '??'))
except:
print('??')
" 2>/dev/null)
if [ -n "$loc" ] && [ "$loc" != "??" ]; then
echo "$loc"
else
echo "??"
fi
}
check_conn() {
T_START=$(date +%s%N)
timeout 1 bash -c "exec 3<>/dev/tcp/$TARGET_IP/$TARGET_PORT; exec 3<&-; exec 3>&-" 2>/dev/null
STATUS=$?
T_END=$(date +%s%N)
if [ $STATUS -eq 0 ]; then
DIFF_MS=$(( (T_END - T_START) / 1000000 ))
echo "$DIFF_MS"
return 0
fi
return 1
}
# Verify genuine foreign connectivity through TLS handshake (2s timeout)
check_foreign() {
echo "" | timeout 2 openssl s_client -connect www.google.com:443 -servername www.google.com >/dev/null 2>&1
return $?
}
# Fetch initial region upon execution
REGION=$(get_region)
while true; do
MS=$(check_conn)
STATUS=$?
if [ $STATUS -eq 0 ]; then
# Keep checking for updated egress regions when alive
NEW_LOC=$(get_region)
if [ "$NEW_LOC" != "??" ] && [ -n "$NEW_LOC" ]; then
REGION="$NEW_LOC"
fi
else
REGION="--"
fi
# Check actual foreign network reachability
check_foreign
FOREIGN_STATUS=$?
# Mark as dropped only after 2 consecutive failures
if [ $FOREIGN_STATUS -eq 0 ]; then
FAIL_COUNT=0
TARGET_STATE="green"
else
FAIL_COUNT=$((FAIL_COUNT + 1))
if [ $FAIL_COUNT -ge 2 ]; then
TARGET_STATE="red"
else
TARGET_STATE="$CURRENT_STATE"
fi
fi
# Determine ANSI color block
if [ "$CURRENT_STATE" != "init" ] && [ "$TARGET_STATE" != "$CURRENT_STATE" ]; then
COLOR_BLOCK="\e[33m█\e[0m"
CURRENT_STATE="$TARGET_STATE"
elif [ "$TARGET_STATE" == "red" ]; then
COLOR_BLOCK="\e[31m█\e[0m"
CURRENT_STATE="red"
else
COLOR_BLOCK="\e[32m█\e[0m"
CURRENT_STATE="green"
fi
# Reset buffer after 10 blocks
if [ $BLOCK_COUNT -ge 10 ]; then
BLOCK_BUFFER=""
BLOCK_COUNT=0
fi
BLOCK_BUFFER="${BLOCK_BUFFER}${COLOR_BLOCK}"
BLOCK_COUNT=$((BLOCK_COUNT + 1))
# In-place refresh on line 0 (with \e[K to clear line tail)
tput cup 0 0
if [ $STATUS -eq 0 ] && [ -n "$MS" ]; then
echo -e "\e[32m${MS} ms [${REGION}]\e[0m\e[K"
else
echo -e "\e[31m--- ms [--]\e[0m\e[K"
fi
# In-place refresh on line 2
tput cup 2 0
echo -e "${BLOCK_BUFFER}\e[K"
sleep "$INTERVAL"
done