Skip to content

Instantly share code, notes, and snippets.

@djeraseit
Forked from rizperdana/scrpwireless.md
Created September 7, 2024 23:39
Show Gist options
  • Save djeraseit/5a67001477b6aa6413af036d3469ff72 to your computer and use it in GitHub Desktop.
Save djeraseit/5a67001477b6aa6413af036d3469ff72 to your computer and use it in GitHub Desktop.
Script to allow your android phone connect wirelessly with your laptop via wifi or phone tethering
#!/bin/bash
# Step 1: Get phone's IP address
echo "Finding phone's IP address..."
PHONE_IP=$(adb shell ip route | awk '{print $9}')
# Check if IP address was found
if [ -z "$PHONE_IP" ]; then
echo "Could not find the phone's IP address. Make sure your phone is connected via USB and USB debugging is enabled."
exit 1
fi
# Step 2: Save the IP address to a file for future use
echo "Saving IP address ($PHONE_IP) to 'phone_ip.txt'..."
echo $PHONE_IP > phone_ip.txt
# Step 3: Enable wireless debugging over Wi-Fi
echo "Enabling wireless debugging on port 5555..."
adb tcpip 5555
sleep 2
# Step 4: Connect to the phone using the IP address found
echo "Connecting to the phone at $PHONE_IP:5555..."
adb connect $PHONE_IP:5555
sleep 2
# Step 5: Prompt to remove USB cable
echo "Please disconnect the USB cable from your phone."
read -p "Once you've removed the USB cable, press Enter to continue..."
# Step 6: Start scrcpy with options -S (stay awake) and -w (wireless)
echo "Starting scrcpy..."
scrcpy -S -w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment