Files
shed/overlay/scripts/commands/icanhazip.nix
pagedmov 8c007c3915 Moved scripts to the overlay folder to be used as packages
All scripts have been moved to the overlay folder in the top level directory

Overlay is now instantiated per configuration to make use of the host variable
2024-11-16 03:42:07 -05:00

19 lines
653 B
Nix

{ pkgs }:
pkgs.writeShellApplication {
name = "icanhazip";
runtimeInputs = with pkgs; [ iproute2 curl gawk coreutils ];
text = ''
if [ $# -eq 0 ]; then
echo "Public IP: $(curl -s icanhazip.com -4)"
ip route | awk '/default/ {print "Default Gateway: " $3} /src/ {print "Local IP: " $9}' | head -n 2
else case $1 in
"-p" ) echo "Public IP: $(curl -s icanhazip.com -4)";;
"-d" ) ip route | awk '/default/ {print $3}';;
"-l" ) ip route | awk '/src/ {print $9}';;
* ) echo "Options: -p, -d or -l for public ip, default gateway, and local ip respectively"; echo "i.e. icanhazip -p"
esac
fi
'';
}