I would like to know what machines connect to my home network. My thought was to have a MySQL database with an entry for each machine, with the timestamp of when I saw it last, and a tally of how many times I have seen it. That is straightforward. My queston is how do I scan for the MACs? I have considered something like this running every 30 minutes:
#! /usr/bin/python
import nmap
nm = nmap.PortScanner()
nm.scan(hosts='10.10.10.0/24', arguments='-n -sP -PE)
hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()]
for host, status, mac in hosts_list:
save(host,status,mac)
... but in order to get the MAC, I need to run this as root
.
- Is there a better way of doing this? (I have considered also if I could get the DHCP records from the router, but that would not find any fixed-ip devices)
- Could I use another tool?
- Is there any security measure i can take running a script in cron as root?