Skip to content

Instantly share code, notes, and snippets.

@syneart
Created January 12, 2021 07:43
Show Gist options
  • Save syneart/3c6f03e40dba88dc367164b91b2c532f to your computer and use it in GitHub Desktop.
Save syneart/3c6f03e40dba88dc367164b91b2c532f to your computer and use it in GitHub Desktop.

Revisions

  1. syneart created this gist Jan 12, 2021.
    20 changes: 20 additions & 0 deletions deviceConnect2Wifi.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/bin/bash
    # This shell script is made by SyneArt <[email protected]>

    # Android Studio default path on Mac
    adb=~/Library/Android/sdk/platform-tools/adb

    function connect() {
    device_id=$1
    device_ip=`${adb} -s ${device_id} shell ip -f inet addr show wlan0 | grep -e "[0-9].*\/[0-9]*" | awk '{ print $2 }' | sed 's/\/[0-9]*//'`
    echo "Android device id: ${device_id}"
    ${adb} -s ${device_id} tcpip 5555
    ${adb} connect ${device_ip}
    }

    while IFS= read -r line; do results_device_id+=("$line"); done < <(${adb} devices | grep -v "devices\|:" | grep "device\|offline" | cut -f 1)
    [[ "${#results_device_id[@]}" -eq "0" ]] && echo "No any android devices need to switch to WiFi debug mode!"
    for ((k=0; k<"${#results_device_id[@]}"; k++))
    do
    connect ${results_device_id[$k]}
    done