いまさらAndroid端末にすばやくWiFiで接続する

なんとなく面倒なのでスクリプトで。

USBで接続のあと #5555 で待たせて再起動する。

「restart」なので、kill-server → start-server は不要。


adb tcpip 5555

IPアドレスをコマンドラインから取得。


ip="$(adb shell ip route | awk '{print $9}')"

そのIPにWiFi接続。


adb connect $ip



 

まとめ

ついでに、開発時には邪魔なスリープもOFFに。


adb shell svc power stayon true

How to prevent an android device from entering sleep (via adb command shell) - Stack Overflow

connect_via_wifi.sh


#!/bin/sh

adb tcpip 5555

sleep 1

ip="$(adb shell ip route | awk '{print $9}')"

adb connect $ip

adb shell svc power stayon true

adb devices -l

端末内 adbd の TCPモード(#5555)が起動している限り再接続が可能。

なので、USB接続なしの状態でも

IPの目処つけて 「adb connect」 でどうぞ。


~ $ adb devices
List of devices attached

~ $ get-oui -v
Renaming ieee-oui.txt to ieee-oui.txt.bak
Fetching OUI data from http://standards-oui.ieee.org/oui/oui.txt
Fetched 4084734 bytes
Opening output file ieee-oui.txt
25968 OUI entries written to file ieee-oui.txt

~ $ sudo arp-scan -l
Interface: en0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.9.5 with 256 hosts (https://github.com/royhills/arp-scan)
192.168.0.1	8a:af:ec:9c:91:08	BUFFALO.INC
192.168.0.2	dc:23:76:3d:9b:75	HTC Corporation
192.168.0.3	d0:27:82:f5:e8:2a	AzureWave Technology Inc.
192.168.0.8	8c:85:00:14:89:d1	Murata Manufacturing Co., Ltd.
192.168.0.4	a2:37:e3:12:9a:88	HTC Corporation
192.168.0.6	33:28:6d:29:7b:72	Google, Inc.

~ $ adb connect 192.168.0.4
connected to 192.168.0.4:5555

~ $ adb devices
List of devices attached
192.168.0.4:5555	device

初回の、USBケーブルなしでTCPモードを起動できないのはセキュリティ絡みでか。

ADBオーバーネットワークでWiFiで複数端末を一括接続する

Android Devices Being Shipped with TCP Port 5555 Enabled - DEV Community 👩‍💻👨‍💻