简体   繁体   中英

How can I detect IP address of local raspberry pi which is connected to wireless LAN in Android?

I have raspberry pi which connected to my network and got its IP with DHCP dynamically.

I need the IP address of the raspberry pi in my Android program for my iot project. In other OS I could use the nmap or arp commands, but I could not find a proper way in Android. I've already read these solutions, but they weren't helpful:

Since the Raspberry Pi is connected to the local network, you can get the list of connected devices and search for the device with the name 'raspberrypi'. This can be done by using socket programming in Java. Try opening up admin panel of your router and look for the hostname of Raspberry Pi(usually raspberrypi) with IP address. That hostname can be used to identify the IP address of the Raspberry Pi from Java code dynamically.

Your problem is similar to the one given in the below link.

How to get IP address and names of all devices in local network on Android

Pi-oi: a Tool for Finding Local IP Address of Your Raspberry Pi

Resolving ip-address of a hostname

There can be may other ways to find the IP address. Just use the one that suits your purpose.

The Android device can determine its own IP. The device knows that the IP of the raspi will be about the same but for the last byte.

So just make a loop where you try to connect, using a Socket, to IP addresses 'around' it's own. Use the SSH port 22.

Within seconds you will know the raspi.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM