I want to discover all devices (host name, MAC address and vendor name) connected to my Wifi network through an android phone. There are no common services running on the devices.
Tried the following methods:
- Pinging all IPs in the subnet takes too long (
inetAddress.isReachable()
). - Sending an
nbstat
request to query theNETBIOs
names works in some devices. Some of them givePortNotOpenException
(port 137 not opened). Some other devices do not haveNETBIOs
name service enabled. Tried using jcifs for android. Was able to fetch host names using
nbtAddress.getByName(ip)
looped over all IP addresses in the subnet. This method gives all hostnames, irrespective of whether they are active or not.
What is the best method to find all ACTIVE devices on a network? Some apps like FING seem to do it.
Edit: I tried to analyze how the android FING app does it.
- Connected a small hotspot with 2 devices. Started discovery in FING and captured packets on wireshark. A series of the following requests are sent(All broadcast):
- Started discovery in FING on a large wifi network (65 k devices) Netbios name service query and response packets are captured. (Unicast and sometimes to broadcast address)
Meanwhile, I try to print the arp entries of my android phone on the IDE.
The number of entries keeps increasing as discovery progresses in FING app.
5 entries before discovery starts
Increases to 1025 entries as the discovery progresses.
Decreases to 150 entries after the discovery is over.
What exactly is happening? There were no ICMP requests. Can ARPRequests be sent in an android application? Please help.