aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-09-10 11:09:36 -0300
committerEuAndreh <eu@euandre.org>2023-09-10 11:09:36 -0300
commit943645fe29f5f15007bb9b1e1c41f71f63b77fbc (patch)
tree58531d38a554c728d378aa97d2dadd228d19cecf /bin
parentetc/nix/configuration.nix: Match "message_size_limit" in Guix (diff)
downloaddotfiles-943645fe29f5f15007bb9b1e1c41f71f63b77fbc.tar.gz
dotfiles-943645fe29f5f15007bb9b1e1c41f71f63b77fbc.tar.xz
bin/getip: Add somewhat working utility
Diffstat (limited to 'bin')
-rwxr-xr-xbin/getip72
1 files changed, 72 insertions, 0 deletions
diff --git a/bin/getip b/bin/getip
new file mode 100755
index 0000000..c351d4f
--- /dev/null
+++ b/bin/getip
@@ -0,0 +1,72 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ getip [-4|-6]
+ getip -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+
+ Options:
+ -4 get IPv4
+ -6 get IPv6 (default)
+ -h, --help show this message
+
+
+ The the internet facing IP address of the current machine.
+
+
+ Examples:
+
+ Expose IPv6::
+
+ $ echo "http://$(getip -6)/sub/" >> index.html
+ EOF
+}
+
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+V=6
+while getopts '46h' flag; do
+ case "$flag" in
+ 4)
+ V=4
+ ;;
+ 6)
+ V=6
+ ;;
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+
+curl -s https://euandre.org/b/ipv"$V"