more robust public ip look up.
This commit is contained in:
+40
-4
@@ -1,8 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
# works consistently if you specify the -4 to force IPv4
|
||||
dig -4 +short A myip.opendns.com @resolver1.opendns.com
|
||||
# there are a few different ways to resolve public-ip,
|
||||
# keep trying until we get a result
|
||||
|
||||
#curl --fail --silent --show-error https://ipinfo.io/ip
|
||||
#echo ""
|
||||
# dig
|
||||
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
|
||||
|
||||
# works consistently if you specify the -6 to force IPv6
|
||||
dig -6 +short AAAA myip.opendns.com @resolver1.opendns.com
|
||||
# there are a few different ways to resolve public-ip,
|
||||
# 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
|
||||
|
||||
# this only works if your crontab uses three spaces for each section,
|
||||
# like the following spacing example:
|
||||
#m h dom mon dow command
|
||||
# quickly generate a script file which will contain all crontab tasks.
|
||||
# optionally takes filename to use, defaults to 'crontasks.sh'.
|
||||
crontasks="$1"
|
||||
|
||||
# quickly generate a script file which will run each crontab task
|
||||
# optionally takes filename to use, otherwise defaults 'crontasks.sh'
|
||||
FILENAME="$1"
|
||||
|
||||
if [ -z "$FILENAME" ]; then
|
||||
FILENAME='crontasks.sh'
|
||||
if [[ -z "$crontasks" ]]; then
|
||||
crontasks='crontasks.sh'
|
||||
fi
|
||||
|
||||
echo "#!/bin/bash" > "$FILENAME"
|
||||
echo "" >> "$FILENAME"
|
||||
# prefix file we are generating
|
||||
echo "#!/bin/bash" > "$crontasks"
|
||||
echo "" >> "$crontasks"
|
||||
|
||||
# list crontab, remove comments and empty lines,
|
||||
# expect cron time formatting to be the first 20 characters,
|
||||
# so drop the 21st character onward to standard out.
|
||||
crontab -l | grep -Ev '^(#|$)' | cut -c 21- >> "$FILENAME"
|
||||
# list crontab, remove comments, convert tabs to space, squeeze the spaces,
|
||||
# then take the sixth field "command" and add it to the file.
|
||||
# could have issues if a task has a "#" in the middle.
|
||||
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