It's not difficult to get a list of all the devices which are connected to the Wi-Fi, for example, ping
all possible hosts in your network, then read the ARP cache table to get mac addresses of devices. Here is an app for this. The hard part is the unconnected devices with their Wi-Fi on, it's nearly impossible on general Android phones(BTW, Linux with proper wireless adapter is most suitable to do such a thing) but there're some exceptions, the theory is your phone will keep sending probe requests(active scanning) which contain BSSID, SSID(specify the known network if any) and your phone's MAC address to update available WiFi list for later connection, for example, below is a probe request packet I captured:
Frame 15: 290 bytes on wire (2320 bits), 290 bytes captured (2320 bits)
Radiotap Header v0, Length 25
802.11 radio information
IEEE 802.11 Beacon frame, Flags: ........C
Type/Subtype: Beacon frame (0x0008)
Frame Control Field: 0x8000
.000 0000 0000 0000 = Duration: 0 microseconds
Receiver address: ff:ff:ff:ff:ff:ff
Destination address: ff:ff:ff:ff:ff:ff
Transmitter address: f4:6a:92:23:30:c0
Source address: f4:ff:92:23:30:c0
BSS Id: f4:fa:92:23:30:c0
.... .... .... 0000 = Fragment number: 0
1010 0011 1101 .... = Sequence number: 2621
Frame check sequence: 0x7037cad2 [correct]
[FCS Status: Good]
IEEE 802.11 wireless LAN management frame
Fixed parameters (12 bytes)
Tagged parameters (225 bytes)
Tag: SSID parameter set: someSSID
Tag: Supported Rates 1(B), 2(B), 5.5(B), 11(B), 6, 9, 12, 18, [Mbit/sec]
Tag: DS Parameter set: Current Channel: 11
Tag: Traffic Indication Map (TIM): DTIM 0 of 0 bitmap
Tag: ERP Information
Tag: Extended Supported Rates 24, 36, 48, 54, [Mbit/sec]
Tag: HT Capabilities (802.11n D1.10)
Tag: HT Information (802.11n D1.10)
Tag: RSN Information
Tag: Vendor Specific: 00:50:f2: WPA Information Element
Tag: Vendor Specific: 00:50:f2: WMM/WME: Parameter Element
Tag: Vendor Specific: 00:0a:eb
Tag: Vendor Specific: 00:50:f2: WPS
To capture these packets, your WiFi adapter need support monitor mode which is rare on Android, but not none, see this project to know supported devices and how. Note that in response to these privacy violations, some OSs(Andord 6+, iOS 8+ AFAIK) have implemented different variants of MAC address randomisation.