question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I determine which devices are available to connect to?

See original GitHub issue

In the example code in the readme, we find the line

device1 = AdbDevice(serial='192.168.0.111:5555', default_timeout_s=9.)

This seems to suggest that in order to use this library to talk to a device, I need to know its IP and port already. Is there a facility in this library to obtain this information? If not, I’d suggest there should be.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JeffLIrioncommented, Nov 8, 2019

I wrote this package to implement ADB shell functionality over TCP. If someone wants to implement that same functionality over USB, including writing tests with complete coverage, then that would be a welcome contribution. But I have no plans to do that myself.

1reaction
ubaierbhatcommented, Nov 7, 2019

I am just trying library as well and I was going to ask the same question. Limiting to tcp connection doesn’t sound nice and there should be a way to get a list of connected devices as well.

This is how I make it work:

You can get the ip address of the device from Settings > About Phone > Status on your phone. Or as Jeff said you can check your router. Or if you are already connected with usb adb shell ip route | awk '{print $9}''

But having just an ip address of your device won’t be enough. You must enable adb connection over tcp first. For this your device needs to be connected with usb and use following adb command: adb tcpip [port] e.g. adb tcpip 5555

AdbDevice(serial='192.168.0.111:5555').connect() is equal to adb connect 192.168.0.111:5555

So the not recommended (as it uses adb commands directly) way to do it will be

import os
from pathlib import Path

from adb_shell.adb_device import AdbDevice
from adb_shell.auth.sign_pythonrsa import PythonRSASigner

# get ip (WLAN only) address of device
ip = str(os.popen("adb shell ip route | awk '{print $9}'").read()).strip()
print(f'IP address: {ip}  ')

# Enable adb over tcp
port = '5555'
os.system(f'adb tcpip {port}')

# Connect (authentication required)
home = str(Path.home())
with open(f'{home}/.android/adbkey') as f:
    priv = f.read()

signer = PythonRSASigner('', priv)
device = AdbDevice(serial=f'{ip}:{port}')
device.connect(rsa_keys=[signer], auth_timeout_s=0.1)

# Send a shell command
response = device.shell('echo hello')
print(response)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Identify Devices on My Network - Lifewire
Open your router's mobile app and look for a tab that lists all the devices connected to your network. It might say Devices...
Read more >
How to see all the devices connected to your network
Use your router's online interface​​ Log into your router to see the most up-to-date information about which devices are connected. Most models ...
Read more >
How to See Who's On Your Wi-Fi - PCMag
You can open your router's management page by typing its IP address in your browser's address bar. Once there, look for an option...
Read more >
3 Ways to See Who Is Connected to Your Wireless Network
1. Open a browser. You can use a web browser to log in to the web interface for your wireless router. You can...
Read more >
How Can I See What Devices Are Connected to My Network?
How to Check How Many Devices Are Connected to My WiFi Using Software ... There is software that allows you to view detailed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found