0

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.

  • Have you considered assigning the devices a static VPN subnet IP by configuring CCD in OpenVPN (client-config-dir)? – JW0914 Mar 12 at 11:48
  • @JW0914 Ah kind of but then I somehow forgot about it. Even though it would require me to check whether I'm connected over VPN or directly, it's probably the closest I can get. Thanks a lot for your suggestion. – skullph Mar 13 at 15:59
  • If you're using a bash script, you could use an if/elif statement in the script in a variety of ways to get the IP. I personally recommend static IPs across the board, as they make a home network much easier to navigate, so one simple solution would be to set static IPs n the router for home network devices, configure OpenVPN with CCD, then use arp, ping, of ifconfig in an if/elif statement within a script. – JW0914 Mar 14 at 16:18
  • @JW0914 Yes, that seems like a good idea, thank you! If you post this as an answer, I will accept it. – skullph Mar 15 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.