If your interface is in IBSS, Mesh point, or AP/P2P Group Owner mode, then you can dump the stations's MAC and their signal level as perceived by your network card with iw dev wlan0 station dump.
As for fetching the MAC from the IP address, a suggestion would be to use the ARP table with ip neigh. Note that you may have to ping the IP address to populate the ARP table.
So, to fetch the RSSI for a node claiming address A, it could be:
MAC="$(ip neigh show to A dev wlan0 | cut -f 3 -d ' ')"
if [ -n "$MAC" ]; then
iw dev wlan0 station get "$MAC" | sed -nre "s@\s*signal:\s*@@p"
else
# no ARP entry. Ping the address and retry.
fi
If, however, your interface is not on this type (e.g. Non-AP sta), then you will have to fiddle with monitor mode, and you have no reliable way to get a MAC address from an IP address (hint: if the station is routing, then it will use the IP of the sender, not his own).
As said before, iwconfig/iwspy/iwlist/iwpriv are deprecated and sucks. they use a kernel API (wireless extensions) which is deprecated and is only implemented for retrocompatibility purpose, and only if enabled in the kernel configuration. Many part of it are thereby faked or lacks many features, including Wi-Fi direct. If you are using Wi-Fi direct, then you are already using the modern nl80211 kernel API, and you should forget about the wext API and iwconfig/iwspy.
And yes, you need the MAC address of the node. Wi-Fi operates at layer 1 and 2 on the OSI model and does not care about the upper layer. An IP and a MAC address serves different purpose and are not the same thing.
iw dev wlan0 station dumpwill list them and their RSSI. And yes,iwspy,iwconfig,iwlistiwprivsucks and are deprecated. – BatchyX Mar 10 at 17:03