Skip to content

Instantly share code, notes, and snippets.

@HQarroum
Last active May 7, 2024 17:05
Show Gist options
  • Save HQarroum/179183a96c5991685d9cd7f0da882385 to your computer and use it in GitHub Desktop.
Save HQarroum/179183a96c5991685d9cd7f0da882385 to your computer and use it in GitHub Desktop.
Using socat to forward traffic from a network interface to the loopback address on which ADB is listening.
#!/bin/bash
set -e
# Installing required packages for the Android SDK
# and the emulator.
sudo apt update -y && \
DEBIAN_FRONTEND=noninteractive sudo apt install -y --no-install-recommends \
socat \
iproute2
# The local ADB port.
ADB_PORT=5555
# Resolving the IP address of the network interface.
LOCAL_IP=$(curl --silent http://169.254.169.254/latest/meta-data/local-ipv4)
# Running socat in the background to forward TCP traffic
# between the network interface and the loopback address.
socat tcp-listen:"$ADB_PORT",bind="$LOCAL_IP",tcp-nodelay,fork tcp:127.0.0.1:"$ADB_PORT" &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment