#!/usr/bin/env etsh : : etsh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; : : " @(#)$Id: 64df03aee04c5315bbc6d1843102526a8d0329e2 $ " : : " The author of this file, J.A. Neitzel , " : " hereby grants it to the public domain. " : : : " Get client/user IPv6 and/or IPv4 address(es). " : : " This command is useful because ifconfig(8) may not " : " reflect whether or not addresses are public. " : : " Exit w/ zero status (true) if request(s) succeed(s). " : " Otherwise, exit w/ non-zero status (false). " : : " usage: myip [-4 | -46 | -6] " : : " Check for correct usage. " : >>$0'' <'' ; : >>$1'' <'' ; killer $0 myip if ! \( $# -eq 0 -o \( \ $# -eq 1 -a \( X$1 = X-4 -o X$1 = X-46 -o X$1 = X-6 \) \ \) \) if { exit } pusage $0 '"[-4 | -46 | -6]"' : " Exit w/ error if which is not found, fails, or curl is not found. " trap : 2 3 if ! { fd2 which which >/dev/null } if { exit } perror $0 '"which: Not found"' if { fd2 which . >/dev/null } if { exit } perror $0 '"which: Invalid results"' if ! { fd2 which curl >/dev/null } if { exit } perror $0 '"curl: Not found"' trap - 2 3 : " Set variables used below. " set C 'curl --fail --silent --show-error' set D 'https://myip6.v6shell.org/' set E 'https://myip.v6shell.org/' set F 'https://myip4.v6shell.org/' : " Default to zero status (true). " set G 0 ; set H 0 ; set I 0 : " Do the work now. " if $# -eq 1 -a X$1 = X-4 goto IPv4 if $# -eq 1 -a X$1 = X-46 goto IPv6orIPv4 : IPv6 echo 'IPv6:' $C $D >/dev/null set G $? if $G -ne 0 if { echo ' Cannot connect via IPv6.' } goto Jump fd2 -f/dev/null -- $C $D | sed 's/^/ /' : fallthrough : Jump if $# -ne 0 exit ; if $G -eq 0 echo : fallthrough : IPv6orIPv4 echo 'IPv6 <-> IPv4:' $C $E >/dev/null set H $? if $H -ne 0 if { echo ' Cannot connect via IPv6 or IPv4.' } goto Jump1 fd2 -f/dev/null -- $C $E | sed 's/^/ /' : fallthrough : Jump1 if $# -ne 0 exit ; if $H -eq 0 echo : fallthrough : IPv4 echo 'IPv4:' $C $F >/dev/null set I $? if $I -ne 0 if { echo ' Cannot connect via IPv4.' } goto Done fd2 -f/dev/null -- $C $F | sed 's/^/ /' : fallthrough : Done if $G -ne 0 -o $H -ne 0 -o $I -ne 0 if { exit } false : zero status