User Tools

Site Tools


docu:tutos:android:adb_tcp_forwarding

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
docu:tutos:android:adb_tcp_forwarding [2020/02/07 11:55]
admin created
docu:tutos:android:adb_tcp_forwarding [2020/02/07 12:34]
admin
Line 1: Line 1:
-==== Forwarding adb over TCP/IP ====+==== Forwarding adb over TCP/IP (Mostly Wifi) ====
  
 Today we are going to learn how to use adb tcp forwarding\\ Today we are going to learn how to use adb tcp forwarding\\
 to access an android phone shell (or screen) using multiple tcp/ip port forwardings\\ to access an android phone shell (or screen) using multiple tcp/ip port forwardings\\
  
-First, connect the phone via usb (this is needed) and issue:+First, **connect the phone via usb** (this is needed) and issue:
 <code bash> <code bash>
 # You can choose any port you want # You can choose any port you want
Line 11: Line 11:
 # Save the phone ip somewhere # Save the phone ip somewhere
 adb shell ifconfig adb shell ifconfig
- 
-# Expose the 5558 port to forward it on 5557 
-adb forward tcp:5558 tcp:5557 
 </code> </code>
  
-Once this is enabled, you can stop using the usb cable\\+Once this is enabled, **you can stop using the usb cable**\\
  
 To connect to the adb device by it's ip address: To connect to the adb device by it's ip address:
 <code bash> <code bash>
 adb connect [YOUR_PHONE_IP]:5557 adb connect [YOUR_PHONE_IP]:5557
 +# or disconnect later
 +adb disconnect [YOUR_PHONE_IP]:5557
 </code> </code>
  
 +You can now access the phone **shell or screen via tcp/ip**
 +<code bash>
 +adb shell
 +scrcpy # gui tool from genymotion to view the phone screen over adb
 +</code>
  
 +\\
 +==== Forwarding adb over USB and TCP/IP ====
 +
 +There can be a case when you want to **use a device connected to a server by usb**\\
 +You can do this easily by enabling tcpip mode on adb and forwarding the port.\\
 +
 +First, **enable tcpip on 5557**, and forward on **server to 5558**
 +<code bash>
 +adb tcpip 5557
 +adb forward tcp:5558 tcp:5557
 +</code>
 +
 +Check forward is working
 +<code bash>adb forward --list</code>
 +
 +Now, you can use ssh forwarding to connect the **phone shell or screen remotely**!!!
 +<code bash>
 +ssh -L 5558:127.0.0.1:5558 [REMOTE_HOST]
 +adb connect 127.0.0.1:5558 # connect locally
 +</code>
 +
 +\\
 +To **reset the tcpip state** issue:
 +<code bash>
 +# If you just want to remove the forwarding but keep tcpip
 +adb forward --remove-all
 +
 +# This will remove all forwardings and restart adb as usb instead of tcpip
 +adb usb
 +</code>
docu/tutos/android/adb_tcp_forwarding.txt · Last modified: 2020/02/07 12:48 by admin