diff --git a/configuration.nix b/configuration.nix index 1bc6a82..569642e 100644 --- a/configuration.nix +++ b/configuration.nix @@ -102,4 +102,46 @@ system.stateVersion = "25.05"; + systemd.timers."scan" = { + wantedBy = [ "timers.target" ]; + timerConfig = { + OnBootSec = "5m"; + OnCalendar = "*:0/5"; + Unit = "scan.service"; + }; + }; + + systemd.services."scan" = { + script = '' + /run/current-system/sw/bin/nmap -sn 192.168.1.0/24 \ + | /run/current-system/sw/bin/awk ' + /Nmap scan report for/ { + if (match($0, /\(([^)]+)\)/)) { + ip = substr($0, RSTART+1, RLENGTH-2) + host = $5 + } else { + ip = $NF + host = "" + } + } + /MAC Address:/ { + mac = $3 + vendor = $0 + sub(/^.*\(/, "", vendor) + sub(/\).*$/, "", vendor) + + print ip "," host "," vendor "," mac + } + ' > "/data/nmap/$(date +%F_%H-%M-%S)-nmap.csv" + ''; + serviceConfig = { + Type = "oneshot"; + User = "root"; + }; + }; + + systemd.tmpfiles.rules = [ + "d /data 777 root root" + "d /data/nmap 777 root root" + ]; }