Skip to content

Instantly share code, notes, and snippets.

@agail
Created January 13, 2022 21:01
Show Gist options
  • Save agail/75d7aacf8870b39d55b23d2972f5ab32 to your computer and use it in GitHub Desktop.
Save agail/75d7aacf8870b39d55b23d2972f5ab32 to your computer and use it in GitHub Desktop.
Activate telnet emergency port on Tomato based firmware
#!/bin/bash
#
# Simple script to trigger the activation of telnet emergency port on Tomato based firmware for SOHO routers
#
device_ip=$1 # Device ip
hold_time=25 # Recommended value 25, increase second by 1 if you have problem to activate the emergency port
max_tries=3 # Wait for device to spawn emergency port
if [ $# -lt 1 ]; then
echo -e "\e[1;90m$(sed -ne '/^#$/,/^$/p' $0)\e[m"
echo -e " ${0##*/} ip-address\n"
exit 1
fi
f_ready () {
read -rsp 'Get ready, press any key to continue ...'
}
f_timer () {
echo
while [ ${hold_time} -gt 0 ]; do
printf "\r\r\e[1APress and hold WPS or Wifi On/Off button for --> \e[1m${hold_time}\e[m <-- seconds, then release\e[K\n"
sleep 1
((hold_time--))
done
printf "\r\r\e[1A\e[94mRelease button!\e[K\e[m\n"
}
f_connect () {
while true; do
if [ $(nc -z -w 3 ${device_ip} 233; echo $?) == 0 ]; then
echo -e "\n\e[94m Once connected enter:\e[m nvram get http_passwd \e[94mto retrieve password\e[m\n"
telnet ${device_ip} 233
break
else
((retry++))
echo -ne "\rAttempting to connect, try ${retry} of ${max_tries} ...\e[K"
sleep 2
fi
if [ ${retry} -eq ${max_tries} ]; then echo -e "\n\e[91mConnection failed, try again ...\n\e[m"; exit; fi
done
}
f_ready
f_timer
f_connect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment