开发者

Gathering mac addresses with Python

开发者 https://www.devze.com 2023-01-04 05:00 出处:网络
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 Pyth

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 i开发者_StackOverflow中文版nside a Django app eventually. Thanks.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消