Is there any way to consistently find out the IP-addresses of specific devices that are connected to a local network (possibly over a VPN)?
Specifically, I'm trying to do the following: I have an openVPN-server running at home and some devices, let's say a laptop and a phone. What I want is a (bash) script such that, whenever both my devices are connected to the same network (maybe to my home network over VPN) I can run that script, for example on my laptop, and it will return the current IP-address of my phone so that I can connect to it via ssh or something similar.
Of course when both my devices are directly connected to the same network (that is without VPN), I can just use arp and check for the MAC-addresses. Unfortunately, that doesn't work over VPN, as far as I know. Additionally, it's not really secure as it's really easy to spoof a device's MAC-address. The only idea I have, that could potentially work, is to first check, if the phone is connected directly to the same network or if it's connected to my home network via VPN. In the former case I could then use arp (which would still be a little insecure), while in the latter I could ssh to the VPN-server and maybe look for the IP-address from there. However that seems kind of cumbersome to me.
I would be thankful for any suggestions.