28 lines
606 B
Bash
Executable File
28 lines
606 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
|
|
output=$( dig +short -x "$IP" )
|
|
else
|
|
output="$IP"
|
|
fi
|
|
|
|
if [[ -z "$output" ]]; then
|
|
exit 1
|
|
fi
|
|
echo "$output"
|