prefer no dnstools solutions
This commit is contained in:
@@ -2,34 +2,48 @@
|
|||||||
|
|
||||||
|
|
||||||
function helpexit() {
|
function helpexit() {
|
||||||
echo "Print your public internet IP address."
|
echo "Print your public internet IP address."
|
||||||
echo "-n return as host name."
|
echo "-n return as host name."
|
||||||
echo "-l display only local addresses."
|
echo "-l display only local addresses."
|
||||||
echo "-j JSON output from ifconfig.co"
|
echo "-j JSON output from ifconfig.co"
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
function locals_only() {
|
function locals_only() {
|
||||||
ip -4 -o addr | awk '!/^[0-9]*: ?lo|link\/ether/ {printf "%18s %s\n", $4, $2}' | sort -k 2
|
ip -4 -o addr | awk '!/^[0-9]*: ?lo|link\/ether/ {printf "%18s %s\n", $4, $2}' | sort -k 2
|
||||||
exit $?
|
exit $?
|
||||||
}
|
}
|
||||||
function ifconfig_service() {
|
function ifconfig_service() {
|
||||||
which curl &>/dev/null && {
|
which jq &>/dev/null && JQ="jq ." || JQ="cat -"
|
||||||
curl -4 ifconfig.co/json; exit $?
|
$CURL ifconfig.co/json | $JQ
|
||||||
}
|
exit $?
|
||||||
which wget &>/dev/null && {
|
|
||||||
wget -q -O - ifconfig.co/json; exit $?
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setup_curl() {
|
||||||
|
which curl &>/dev/null && {
|
||||||
|
CURL="curl -s -4"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
which wget &>/dev/null && {
|
||||||
|
CURL="wget -q -O - "
|
||||||
|
return
|
||||||
|
}
|
||||||
|
echo "No curl or wget present" >2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for (( i=1; i<=$#; i++ )); do
|
for (( i=1; i<=$#; i++ )); do
|
||||||
[[ "${!i}" = "--help" ]] && helpexit
|
[[ "${!i}" = "--help" ]] && helpexit
|
||||||
[[ "${!i}" = "-h" ]] && helpexit
|
[[ "${!i}" = "-h" ]] && helpexit
|
||||||
done
|
done
|
||||||
for (( i=1; i<=1; i++ )); do
|
for (( i=1; i<=1; i++ )); do
|
||||||
[[ "${!i}" = "-n" ]] && { NAME=1; continue; }
|
[[ "${!i}" = "-n" ]] && { NAME=1; continue; }
|
||||||
[[ "${!i}" = "-l" ]] && { LOCAL=1; continue; }
|
[[ "${!i}" = "-l" ]] && { LOCAL=1; continue; }
|
||||||
[[ "${!i}" = "-j" ]] && { JSON=1; continue; }
|
[[ "${!i}" = "-j" ]] && { JSON=1; continue; }
|
||||||
done
|
done
|
||||||
|
|
||||||
|
setup_curl
|
||||||
|
|
||||||
if [[ "$LOCAL" -eq 1 ]]; then
|
if [[ "$LOCAL" -eq 1 ]]; then
|
||||||
locals_only
|
locals_only
|
||||||
@@ -39,18 +53,16 @@ if [[ "$JSON" -eq 1 ]]; then
|
|||||||
ifconfig_service
|
ifconfig_service
|
||||||
fi
|
fi
|
||||||
|
|
||||||
which dig &> /dev/null || {
|
IP=$( $CURL ifconfig.co/ip )
|
||||||
echo Install apt dnsutils >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
IP=$( dig +short myip.opendns.com @resolver1.opendns.com )
|
|
||||||
if [[ -z "$IP" ]]; then
|
if [[ -z "$IP" ]]; then
|
||||||
IP=$( curl -s -4 ifconfig.co/ip )
|
which dig &> /dev/null || {
|
||||||
|
echo Install apt dnsutils >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
IP=$( dig +short myip.opendns.com @resolver1.opendns.com )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$NAME" -eq 1 ]]; then
|
if [[ "$NAME" -eq 1 ]]; then
|
||||||
output=$( dig +short -x "$IP" )
|
output=$( dig +short -x "$IP" )
|
||||||
else
|
else
|
||||||
output="$IP"
|
output="$IP"
|
||||||
|
|||||||
Reference in New Issue
Block a user