Skip to content

Instantly share code, notes, and snippets.

@pingbird
Last active March 3, 2022 23:52
Show Gist options
  • Save pingbird/abcc8c709dc748d979cb16d239cd8c9f to your computer and use it in GitHub Desktop.
Save pingbird/abcc8c709dc748d979cb16d239cd8c9f to your computer and use it in GitHub Desktop.
#!/usr/bin/pwsh
# ADB wifi tool, works on both Windows and Linux!
#
# 1. Finds the phone's IP address on wifi through an existing adb over usb connection
# 2. Puts the phone into TCP/IP mode
# 3. Instructs adb to connect to the phone using its IP address
$interface = adb shell ip addr show wlan0 | Out-String;
if (-not $?) {
Write-Error 'Error running `adb shell ip addr show wlan0`, is it connected to wifi?';
return 1;
}
adb tcpip 5555
if (-not $?) {
Write-Error 'Error running `adb tcpip 5555`';
return 1;
}
$result = $interface -match 'inet (\d+\.\d+\.\d+\.\d+)'
if (-not $result) {
Write-Error 'Could not find ip address of wireless interface';
Write-Error "ip addr: $interface";
return 1;
}
$ip = $Matches[1];
adb connect $ip
if (-not $?) {
Write-Error "Error running ``adb connect $ip``";
return 1;
}
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment