0-TEST-CONNECT.BAT 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. @echo off
  2. chcp 65001 >nul
  3. setlocal enabledelayedexpansion
  4. echo ========================================
  5. echo Test ADB Connection
  6. echo ========================================
  7. echo.
  8. REM Get the directory where this batch file is located
  9. set "SCRIPT_DIR=%~dp0"
  10. set "PROJECT_ROOT=%SCRIPT_DIR%.."
  11. REM Use ADB from project root adb-tools directory
  12. set "ADB_PATH=%PROJECT_ROOT%\adb-tools\adb.exe"
  13. REM Check if local ADB exists, otherwise fallback to system PATH
  14. if not exist "%ADB_PATH%" (
  15. echo Warning: Local ADB not found at %ADB_PATH%
  16. echo Falling back to system PATH...
  17. set "ADB_PATH=adb"
  18. )
  19. echo [0/6] Using ADB: %ADB_PATH%
  20. echo.
  21. echo Please enter the last two digits of the IP address:
  22. set /p IP_LAST_TWO="Last two digits (e.g., 0.15): "
  23. if "%IP_LAST_TWO%"=="" (
  24. echo Error: IP address cannot be empty
  25. pause
  26. exit /b 1
  27. )
  28. set DEVICE_IP=192.168.%IP_LAST_TWO%
  29. set DEVICE_PORT=5555
  30. set DEVICE_ADDRESS=%DEVICE_IP%:%DEVICE_PORT%
  31. echo.
  32. echo Connecting to %DEVICE_ADDRESS%...
  33. echo.
  34. echo [1/6] Check if ADB is available...
  35. "%ADB_PATH%" version >nul 2>&1
  36. if errorlevel 1 (
  37. echo Error: ADB not found at: %ADB_PATH%
  38. echo Please ensure adb.exe exists in %PROJECT_ROOT%\adb-tools\ directory
  39. pause
  40. exit /b 1
  41. )
  42. echo ADB is available
  43. echo.
  44. echo [2/6] Test network connectivity (ping %DEVICE_IP%)...
  45. ping -n 2 %DEVICE_IP% >nul 2>&1
  46. if errorlevel 1 (
  47. echo Cannot ping %DEVICE_IP%
  48. echo Possible reasons: Phone and computer not on same network, or phone is off
  49. echo.
  50. ) else (
  51. echo Network connectivity OK
  52. echo.
  53. )
  54. echo [3/6] Check if port %DEVICE_PORT% is open...
  55. powershell -Command "Test-NetConnection -ComputerName %DEVICE_IP% -Port %DEVICE_PORT% -InformationLevel Quiet" >nul 2>&1
  56. if errorlevel 1 (
  57. echo Port %DEVICE_PORT% may not be open or blocked by firewall
  58. echo.
  59. ) else (
  60. echo Port %DEVICE_PORT% is accessible
  61. echo.
  62. )
  63. echo [4/6] Disconnect old connection (if any)...
  64. "%ADB_PATH%" disconnect %DEVICE_ADDRESS% >nul 2>&1
  65. timeout /t 1 /nobreak >nul
  66. echo Attempting to connect %DEVICE_ADDRESS%...
  67. "%ADB_PATH%" connect %DEVICE_ADDRESS%
  68. set CONNECT_RESULT=%ERRORLEVEL%
  69. echo.
  70. if %CONNECT_RESULT% equ 0 (
  71. echo Connection command completed
  72. echo.
  73. timeout /t 2 /nobreak >nul
  74. ) else (
  75. echo.
  76. echo Connection failed (Error code: %CONNECT_RESULT%)
  77. echo.
  78. echo ========================================
  79. echo Troubleshooting Steps:
  80. echo ========================================
  81. echo 1. Enable "Developer Options" on phone
  82. echo - Settings ^> About phone ^> Tap "Build number" 7 times
  83. echo.
  84. echo 2. Enable "USB debugging"
  85. echo - Settings ^> Developer options ^> USB debugging
  86. echo.
  87. echo 3. Enable "Wireless debugging" or "Network ADB debugging"
  88. echo - Settings ^> Developer options ^> Wireless debugging
  89. echo - Or: Settings ^> Developer options ^> Network ADB debugging
  90. echo - Confirm port is %DEVICE_PORT%
  91. echo.
  92. echo 4. If phone doesn't have "Wireless debugging" option, try:
  93. echo a) Connect phone to computer via USB
  94. echo b) Run: 0-ENABLE-TCPIP.BAT
  95. echo c) Unplug USB, then run this script again
  96. echo.
  97. echo 5. Check if phone and computer are on same Wi-Fi network
  98. echo.
  99. echo 6. Disable phone firewall or allow ADB through firewall
  100. echo.
  101. )
  102. echo [5/6] Check device list...
  103. echo.
  104. "%ADB_PATH%" devices
  105. echo.
  106. echo ========================================
  107. echo Test completed
  108. echo ========================================
  109. pause