🔒 Closed Ps1 command for adb wifi

Status
Not open for further replies.

Katipunero-

Honorary Poster
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;
 
Status
Not open for further replies.

About this Thread

  • 0
    Replies
  • 342
    Views
  • 1
    Participants
Last reply from:
Katipunero-

Online now

Members online
1,006
Guests online
1,124
Total visitors
2,130

Forum statistics

Threads
2,276,159
Posts
28,967,949
Members
1,231,144
Latest member
jonreipogi
Back
Top