#!/bin/bash
#Modify this with your IP range
MY_IP_RANGE="192\.168\.1\.102"
#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
然后直接把文件拖动终端中去。。
直接把 aa.sh 拖入到终端里面。
注意事项:
如果 没有成功报出问题::
Permission denied。就是没有权限。
解决办法:
修改该文件adbwifi.sh 的权限 :使用命令:
chmod 777 adbwifi.sh
然后还是没有找到设备。。
这时就要配置adb环境了。。
一、终端中输入 cd ~
二、输入touch .bash_profile 回车
三、输入open -e .bash_profile
回车后会在TextEdit中打开这个文件(如果未配置过环境变量,应该是个空白文件)。
export PATH=${PATH}:/Users/techstan/Downloads/adt-bundle-mac-x86_64-20140702/sdk/platform-tools
//这是我的路径,根据自己的路径修改
保存,退出TextEdit(一定要退出哦)。关闭终端并推出。
然后再输入终端输入adb测试。。
没有问题直接再执行adbwifi.sh文件
sh /Users/techstan/Desktop/adbwifi.sh