使用Python收集mac地址
有没有一种使用Python收集本地网络上机器的mac地址的好方法?如果有帮助的话,我正在尝试从网络的 DHCP 服务器执行这个 python 脚本。我是 Python 新手,但查看 DHCP 租约文件以获取此信息会是一个坏主意吗?我最终想在 Django 应用程序中使用它。谢谢。
is there a good way to gather the mac addresses of machines on a local network using Python. If it helps I'm trying to execute this python script from the DHCP server for the network. I'm new to Python but would it be a bad idea to look at the DHCP leases file for this info? I'd like to use this inside a Django app eventually. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是运行一个可以实现此目的并解析其输出的工具(例如 nmap)。根据您的需要,您可以定期运行它并保留包含 mac 地址的文件。
假设您的所有机器都在其中,查看租赁文件可能会起作用。如果您想主动寻找机器,请执行 nmap 扫描。
The easiest thing to do would be to run a tool that can achieve this and parse its output (e.g. nmap). Depending on your needs, you could run it periodically and keep a file with the mac addresses.
Looking at the leases file could work, assuming that all your machines are in there. If you want to actively look for machines, do a nmap scan.
确实是一个unix问题(有人会假设)
您可以查看注册的arp地址“/sbin/arp -a”或DHCP租约表。如果您使用 arp 路由,您将找到系统最近接收/发送数据包的地址,DHCP 租用表将使您能够查看所有内容。但如果它是静态配置的,则不会显示。
Really a unix question (one will assume)
You can either look at the arp addresses registered "/sbin/arp -a" or a DHCP lease table. If you go the arp route you will on find addresses that your system has recently received/sent packets to, the DHCP lease table will give you the ability to see everything. Though if it's static configured it won't show up.