nix: add subnet

This commit is contained in:
Astro 2021-02-25 02:28:43 +01:00
parent b1fddd0ba7
commit bf297cd5d7
1 changed files with 20 additions and 0 deletions

20
nix/subnet.nix Normal file
View File

@ -0,0 +1,20 @@
{ pkgs ? import <nixpkgs> {}
}:
{
# 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
''
);
}