Skip to content

Instantly share code, notes, and snippets.

@SuggonM
Last active March 14, 2026 04:59
Show Gist options
  • Select an option

  • Save SuggonM/82c983a8b408019d2d1211ffa3aecef0 to your computer and use it in GitHub Desktop.

Select an option

Save SuggonM/82c983a8b408019d2d1211ffa3aecef0 to your computer and use it in GitHub Desktop.
Restart wireless debugging (ADB) in port 5555 with Termux (no root)

Requirements:

  • Packages: android-tools, nmap
  • Apps: Termux:API (for termux-notification)

Optional:

  • Termux:Boot: Run the script at boot (preferably, add some delay)
  • Termux:Widget: Run the script from a home screen shortcut

Tips:

  • Enable wireless debugging before port scanning begins. If no port is found, tap the script notification to rerun the scan.
  • Add "Wireless debugging" from Quick settings developer tiles to toggle wireless debugging from the notifications pane.
  • It's a good idea to semi-automate the script using one of the termux apps listed above.
#!/data/data/com.termux/files/usr/bin/bash
termux-notification --id 1 -t "Scanning for ADB port..."
adb_port=$(nmap -sT -p30000-50000 --open localhost | grep -m1 -oP "^\d+")
if [[ -z $adb_port ]]; then
termux-notification --id 1 -t "No debug port detected" -c "Tap to rescan." --action "$(realpath $0)"
exit
fi
termux-notification --id 1 -t "ADB port detected: $adb_port. Restarting ADB..."
adb connect localhost:$adb_port
adb tcpip 5555
adb disconnect
sleep 1 # wait for emulator-5554 device
adb shell settings put global adb_wifi_enabled 0
termux-notification --id 1 -t "Successfully restarted ADB in port 5555"
@SuggonM
Copy link
Author

SuggonM commented Feb 23, 2026

Can't find how to add description to gists so here's the gist of this script:

  1. Poll through all possible wireless debugging ports
  2. Connect ADB via the discovered port
  3. Restart it in port 5555
  4. Disconnect the port found earlier
  5. Disable wireless debugging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment