Skip to content

Instantly share code, notes, and snippets.

@stormzhang
Created August 28, 2014 00:52
Show Gist options
  • Select an option

  • Save stormzhang/6fa157ceb7980a25fbf0 to your computer and use it in GitHub Desktop.

Select an option

Save stormzhang/6fa157ceb7980a25fbf0 to your computer and use it in GitHub Desktop.

Revisions

  1. stormzhang created this gist Aug 28, 2014.
    35 changes: 35 additions & 0 deletions adbwifi.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #!/bin/bash

    #Modify this with your IP range
    MY_IP_RANGE="192\.168\.1"

    #You usually wouldn't have to modify this
    PORT_BASE=5555

    #List the devices on the screen for your viewing pleasure
    adb devices
    echo

    #Find USB devices only (no emulators, genymotion or connected devices
    declare -a deviceArray=(`adb devices -l | grep -v emulator | grep -v vbox | grep -v "${MY_IP_RANGE}" | grep " device " | awk '{print $1}'`)

    echo "found ${#deviceArray[@]} device(s)"
    echo

    for index in ${!deviceArray[*]}
    do
    echo "finding IP address for device ${deviceArray[index]}"
    IP_ADDRESS=$(adb -s ${deviceArray[index]} shell ifconfig wlan0 | awk '{print $3}')

    echo "IP address found : $IP_ADDRESS "

    echo "Connecting..."
    adb -s ${deviceArray[index]} tcpip $(($PORT_BASE + $index))
    adb -s ${deviceArray[index]} connect "$IP_ADDRESS:$(($PORT_BASE + $index))"

    echo
    echo
    done

    adb devices -l
    #exit