diff --git a/nix/subnet.nix b/nix/subnet.nix new file mode 100644 index 000000000..4a4ea60 --- /dev/null +++ b/nix/subnet.nix @@ -0,0 +1,20 @@ +{ pkgs ? import {} +}: + +{ + # List of all IP addresses in a subnet + range = subnet: + import ( + pkgs.runCommandLocal "subnet-${subnet}.nix" { + nativeBuildInputs = [ pkgs.nmap ]; + } '' + ( + echo "[" + for i in $(nmap -sL ${pkgs.lib.optionalString (builtins.match ".*:.*" subnet != null) "-6"} ${subnet} -n -oG - | grep Status: | cut -d " " -f 2); do + echo \"$i\" + done + echo "]" + ) > $out + '' + ); +}