在python中从MAC地址检测IP地址
我有一个 Raspberry Pi,它与同一 LAN 上的其他两个设备进行通信。因为这不是我的网络,所以我无法为设备提供静态 IP。当它们翻转时,我必须找到新的 IP 并在两个 configobj 配置页面中更新它们。
我想编写一个程序来扫描网络中的两个设备,当它们更改 IP 时,使用新地址修改两个配置文件并重新启动需要它们的程序。
我知道如何使用 configobj 用新的 IP 更新 .conf 文件,但如何从已知的 MAC 地址获取 IP 地址?
这两个设备无法修改以报告其地址,因此我必须从树莓派中检测它。
所以我需要知道的是:
- 我可以使用MAC地址在python中检测IP吗?以及
- 如何从另一个python程序重新启动程序?在 Linux 控制台中,我将使用“sudo systemctl restart weewx”。我可以在 Python 中做到这一点吗?
谢谢!
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:
- Can I detect an IP in python using a MAC address, and
- 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论