aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
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"