What's new

Ps1 command for adb wifi

Katipunero-

Eternal Poster
Joined
Mar 22, 2020
Posts
790
Reaction
318
Points
312
Code:
#!/usr/bin/pwsh

# ADB wifi tool
#
# 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 'Phone not connected to wifi';
    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;
 

Similar threads

Back
Top