Jekyll2022-07-27T05:59:47+00:00https://trav.is/feed.xmlTravis MortonJust some ramblingsADB over TCP/IP over Zerotier2019-11-05T00:00:00+00:002019-11-05T00:00:00+00:00https://trav.is/adb-over-tcpip-over-zerotier<p>While working on an Android device in the field, I usually find myself needing to connect via ADB wirelessly. This is where the standard TCP/IP mode of ADB comes in handy, although when testing outside of wifi range this is useless since ADB needs to be on the same LAN. Luckily, Zerotier does just that for us so let’s see it in practice.</p> <h1 id="access-on-wifi">Access on Wifi</h1> <p>First, get ADB running in TCP/IP mode on each device you want to test. Plug in the device to USB and connect to wifi. Take note of the private IP, either from your router or from the settings menu. Then, issue the following commands:</p> <div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">&gt;</span> adb usb <span class="o">&gt;</span> adb tcpip 5555 </code></pre></div></div> <p><em>unplug your device from usb</em></p> <div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">&gt;</span> adb connect &lt;IP&gt;:5555 </code></pre></div></div> <p>Now you should see it in your devices list:</p> <div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">&gt;</span> adb devices List of devices attached 192.168.50.52:5555 device </code></pre></div></div> <p>To get a shell just specify the device and port:</p> <div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">&gt;</span> adb <span class="nt">-s</span> 192.168.50.52:5555 shell </code></pre></div></div> <p>Now follow the same steps for each device you want to connect.</p> <h1 id="access-on-cell">Access on Cell</h1> <p>Using Zerotier we can create a private LAN across multiple physical LANs. Create a Zerotier network at <a href="https://my.zerotier.com">https://my.zerotier.com</a>. In this example, the subnet is 10.242.0.0/16. From a command line join the network (or from a GUI if your OS supports it):</p> <div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">&gt;</span> <span class="nb">sudo </span>zerotier-cli <span class="nb">join</span> &lt;network_id&gt; </code></pre></div></div> <p>Now, install the zerotier APK. If your device has a screen and Google Play Services, just download this from the Google Play Store. If not, you will need to pull the APK from a device with Google Play Services and use <a href="https://github.com/Genymobile/scrcpy">scrcpy</a> to open the Zerotier app to join the same network. Make sure to authorize each from the <a href="https://my.zerotier.com">web portal</a>.</p> <div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">&gt;</span> adb <span class="nt">-s</span> 192.168.50.52:5555 <span class="nb">install </span>zerotier.apk <span class="o">&gt;</span> scrcpy <span class="nt">-s</span> 192.168.50.52:5555 </code></pre></div></div> <p>Once the device is authorized on the web portal, connect to the zerotier IP given using the same steps from above. You may need to send traffic over the route to initialize it.</p> <div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">&gt;</span> ping 10.242.206.180 <span class="o">&gt;</span> adb connect 10.242.206.180:5555 <span class="o">&gt;</span> scrcpy <span class="nt">-s</span> 10.242.206.180:5555 </code></pre></div></div> <p>Now, feel free to turn off wifi, however latency will go up and scrcpy will be hard to use (but you will still have an ADB shell). This is now using ADB over TCP/IP over a cell connection!</p>While working on an Android device in the field, I usually find myself needing to connect via ADB wirelessly. This is where the standard TCP/IP mode of ADB comes in handy, although when testing outside of wifi range this is useless since ADB needs to be on the same LAN. Luckily, Zerotier does just that for us so let’s see it in practice.