| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- @echo off
- chcp 65001 >nul
- setlocal enabledelayedexpansion
- echo ========================================
- echo Test ADB Connection
- echo ========================================
- echo.
- REM Get the directory where this batch file is located
- set "SCRIPT_DIR=%~dp0"
- set "PROJECT_ROOT=%SCRIPT_DIR%.."
- REM Use ADB from project root adb-tools directory
- set "ADB_PATH=%PROJECT_ROOT%\adb-tools\adb.exe"
- REM Check if local ADB exists, otherwise fallback to system PATH
- if not exist "%ADB_PATH%" (
- echo Warning: Local ADB not found at %ADB_PATH%
- echo Falling back to system PATH...
- set "ADB_PATH=adb"
- )
- echo [0/6] Using ADB: %ADB_PATH%
- echo.
- echo Please enter the last two digits of the IP address:
- set /p IP_LAST_TWO="Last two digits (e.g., 0.15): "
- if "%IP_LAST_TWO%"=="" (
- echo Error: IP address cannot be empty
- pause
- exit /b 1
- )
- set DEVICE_IP=192.168.%IP_LAST_TWO%
- set DEVICE_PORT=5555
- set DEVICE_ADDRESS=%DEVICE_IP%:%DEVICE_PORT%
- echo.
- echo Connecting to %DEVICE_ADDRESS%...
- echo.
- echo [1/6] Check if ADB is available...
- "%ADB_PATH%" version >nul 2>&1
- if errorlevel 1 (
- echo Error: ADB not found at: %ADB_PATH%
- echo Please ensure adb.exe exists in %PROJECT_ROOT%\adb-tools\ directory
- pause
- exit /b 1
- )
- echo ADB is available
- echo.
- echo [2/6] Test network connectivity (ping %DEVICE_IP%)...
- ping -n 2 %DEVICE_IP% >nul 2>&1
- if errorlevel 1 (
- echo Cannot ping %DEVICE_IP%
- echo Possible reasons: Phone and computer not on same network, or phone is off
- echo.
- ) else (
- echo Network connectivity OK
- echo.
- )
- echo [3/6] Check if port %DEVICE_PORT% is open...
- powershell -Command "Test-NetConnection -ComputerName %DEVICE_IP% -Port %DEVICE_PORT% -InformationLevel Quiet" >nul 2>&1
- if errorlevel 1 (
- echo Port %DEVICE_PORT% may not be open or blocked by firewall
- echo.
- ) else (
- echo Port %DEVICE_PORT% is accessible
- echo.
- )
- echo [4/6] Disconnect old connection (if any)...
- "%ADB_PATH%" disconnect %DEVICE_ADDRESS% >nul 2>&1
- timeout /t 1 /nobreak >nul
- echo Attempting to connect %DEVICE_ADDRESS%...
- "%ADB_PATH%" connect %DEVICE_ADDRESS%
- set CONNECT_RESULT=%ERRORLEVEL%
- echo.
- if %CONNECT_RESULT% equ 0 (
- echo Connection command completed
- echo.
- timeout /t 2 /nobreak >nul
- ) else (
- echo.
- echo Connection failed (Error code: %CONNECT_RESULT%)
- echo.
- echo ========================================
- echo Troubleshooting Steps:
- echo ========================================
- echo 1. Enable "Developer Options" on phone
- echo - Settings ^> About phone ^> Tap "Build number" 7 times
- echo.
- echo 2. Enable "USB debugging"
- echo - Settings ^> Developer options ^> USB debugging
- echo.
- echo 3. Enable "Wireless debugging" or "Network ADB debugging"
- echo - Settings ^> Developer options ^> Wireless debugging
- echo - Or: Settings ^> Developer options ^> Network ADB debugging
- echo - Confirm port is %DEVICE_PORT%
- echo.
- echo 4. If phone doesn't have "Wireless debugging" option, try:
- echo a) Connect phone to computer via USB
- echo b) Run: 0-ENABLE-TCPIP.BAT
- echo c) Unplug USB, then run this script again
- echo.
- echo 5. Check if phone and computer are on same Wi-Fi network
- echo.
- echo 6. Disable phone firewall or allow ADB through firewall
- echo.
- )
- echo [5/6] Check device list...
- echo.
- "%ADB_PATH%" devices
- echo.
- echo ========================================
- echo Test completed
- echo ========================================
- pause
|