Files
q-tools/web/whatismyip
2017-04-26 09:06:06 +03:00

24 lines
535 B
Bash
Executable File

#!/bin/bash
function helpexit() {
echo "Print your public internet IP address."
echo "-n return as host name."
exit
}
for (( i=1; i<=$#; i++ )); do
[[ "${!i}" = "--help" ]] && helpexit
[[ "${!i}" = "-h" ]] && helpexit
[[ "${!i}" = "-n" ]] && { NAME=1; continue; }
done
IP=$( dig +short myip.opendns.com @resolver1.opendns.com )
if [[ "$NAME" -eq 1 ]]; then
dig +short -x "$IP"
else
echo $IP
fi