more robust public ip look up.
This commit is contained in:
+40
-4
@@ -1,8 +1,44 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# works consistently if you specify the -4 to force IPv4
|
# there are a few different ways to resolve public-ip,
|
||||||
dig -4 +short A myip.opendns.com @resolver1.opendns.com
|
# keep trying until we get a result
|
||||||
|
|
||||||
#curl --fail --silent --show-error https://ipinfo.io/ip
|
# dig
|
||||||
#echo ""
|
if [[ -n $(command -v "dig") ]]; then
|
||||||
|
# via opendns
|
||||||
|
address=$(dig "@resolver1.opendns.com" -4 "myip.opendns.com" "A" "+short")
|
||||||
|
if [[ "$?" -ne "0" ]]; then
|
||||||
|
# dig was unsuccessful
|
||||||
|
echo "$address" 1>&2
|
||||||
|
address=""
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# curl
|
||||||
|
if [[ -z "$address" ]] && [[ -n $(command -v "curl") ]]; then
|
||||||
|
# via ipinfo.io
|
||||||
|
address=$(curl -4 --fail --silent --show-error "https://ipinfo.io/ip")
|
||||||
|
|
||||||
|
if [[ -z "$address" ]]; then
|
||||||
|
# via google
|
||||||
|
address=$(curl -4 --fail --silent --show-error "https://domains.google.com/checkip")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# wget
|
||||||
|
if [[ -z "$address" ]] && [[ -n $(command -v "wget") ]]; then
|
||||||
|
# via ipinfo.io
|
||||||
|
address=$(wget -4 --quiet --output-document - "https://ipinfo.io/ip")
|
||||||
|
|
||||||
|
if [[ -z "$address" ]]; then
|
||||||
|
# via google
|
||||||
|
address=$(wget -4 --quiet --output-document - "https://domains.google.com/checkip")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$address" ]]; then
|
||||||
|
echo "$address"
|
||||||
|
else
|
||||||
|
echo 'Tried everything, unable to resolve IP address.' 1>&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
|||||||
+41
-2
@@ -1,5 +1,44 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# works consistently if you specify the -6 to force IPv6
|
# there are a few different ways to resolve public-ip,
|
||||||
dig -6 +short AAAA myip.opendns.com @resolver1.opendns.com
|
# keep trying until we get a result
|
||||||
|
|
||||||
|
# dig
|
||||||
|
if [[ -n $(command -v "dig") ]]; then
|
||||||
|
# via opendns
|
||||||
|
address=$(dig "@resolver1.opendns.com" -6 "myip.opendns.com" "AAAA" "+short")
|
||||||
|
if [[ "$?" -ne "0" ]]; then
|
||||||
|
# dig was unsuccessful
|
||||||
|
echo "$address" 1>&2
|
||||||
|
address=""
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# curl
|
||||||
|
if [[ -z "$address" ]] && [[ -n $(command -v "curl") ]]; then
|
||||||
|
# via ipinfo.io
|
||||||
|
address=$(curl -6 --fail --silent --show-error "https://v6.ipinfo.io/ip")
|
||||||
|
|
||||||
|
if [[ -z "$address" ]]; then
|
||||||
|
# via google
|
||||||
|
address=$(curl -6 --fail --silent --show-error "https://domains.google.com/checkip")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# wget
|
||||||
|
if [[ -z "$address" ]] && [[ -n $(command -v "wget") ]]; then
|
||||||
|
# via ipinfo.io
|
||||||
|
address=$(wget -6 --quiet --output-document - "https://v6.ipinfo.io/ip")
|
||||||
|
|
||||||
|
if [[ -z "$address" ]]; then
|
||||||
|
# via google
|
||||||
|
address=$(wget -6 --quiet --output-document - "https://domains.google.com/checkip")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$address" ]]; then
|
||||||
|
echo "$address"
|
||||||
|
else
|
||||||
|
echo 'Tried everything, unable to resolve IP address.' 1>&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
|||||||
+16
-16
@@ -1,24 +1,24 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# this only works if your crontab uses three spaces for each section,
|
# quickly generate a script file which will contain all crontab tasks.
|
||||||
# like the following spacing example:
|
# optionally takes filename to use, defaults to 'crontasks.sh'.
|
||||||
#m h dom mon dow command
|
crontasks="$1"
|
||||||
|
|
||||||
# quickly generate a script file which will run each crontab task
|
if [[ -z "$crontasks" ]]; then
|
||||||
# optionally takes filename to use, otherwise defaults 'crontasks.sh'
|
crontasks='crontasks.sh'
|
||||||
FILENAME="$1"
|
|
||||||
|
|
||||||
if [ -z "$FILENAME" ]; then
|
|
||||||
FILENAME='crontasks.sh'
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "#!/bin/bash" > "$FILENAME"
|
# prefix file we are generating
|
||||||
echo "" >> "$FILENAME"
|
echo "#!/bin/bash" > "$crontasks"
|
||||||
|
echo "" >> "$crontasks"
|
||||||
|
|
||||||
# list crontab, remove comments and empty lines,
|
# list crontab, remove comments, convert tabs to space, squeeze the spaces,
|
||||||
# expect cron time formatting to be the first 20 characters,
|
# then take the sixth field "command" and add it to the file.
|
||||||
# so drop the 21st character onward to standard out.
|
# could have issues if a task has a "#" in the middle.
|
||||||
crontab -l | grep -Ev '^(#|$)' | cut -c 21- >> "$FILENAME"
|
crontab -l | grep -o '^[^#]*' | tr "\t" ' ' | tr -s ' ' | cut -s -d ' ' -f 6- >> "$crontasks"
|
||||||
|
|
||||||
chmod +x "$FILENAME"
|
echo "" >> "$crontasks"
|
||||||
|
|
||||||
|
# make the file executable, so we are good to go
|
||||||
|
chmod +x "$crontasks"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user