0

I have a Raspberry Pi that communicates with two other devices on the same LAN. Because it's not my network I can't give the devices static IPs. When they roll over I have to find the new IPs and update them in two configobj configuration pages.

I'd like to write a program that scans the network for the two devices and when they change IPs, modify the two configuration files with the new addresses and restart the programs that need them.

I know how to use configobj to update the .conf files with the new IPs, but how do I get the IP address from the known MAC addresses?

The two devices can't be modified to report their address so I have to detect it from the raspberry pi.

So what I need to know is:

  1. Can I detect an IP in python using a MAC address, and
  2. How can I restart a program from another python program? In the Linux console I would use 'sudo systemctl restart weewx'. Can I do that from within Python?

Thanks!

  • 1) there is protocol called ARP, which resolve Mac id to dynamic ip 2) the command you put is service restart not program, when you mentioned program, could you provide what is program, is it thread, process, subprocess etc – Vardhman Patil Mar 24 '22 at 05:25
  • Have you considered using mDNS/avahi? It is running by default on Raspberry Pis. If your RaspberryPi has its hostname set to, say, *"simon"* in `raspi-config`, you can ping it and `ssh` into it using `simon.local` as its name rather than using IP. – Mark Setchell Mar 24 '22 at 07:35

0 Answers0