views:

52

answers:

2

Hi, 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.

+1  A: 

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.

koblas
+1  A: 

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.

Unknown