-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
51 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,57 @@ | ||
#!/bin/bash | ||
|
||
# ensure we have connectivity before attempting to detect external ip address | ||
source /root/checkvpnconn.sh "google.com" "443" | ||
|
||
# define name servers to connect to in order to get external ip address | ||
pri_external_ip_ns="ns1.google.com" | ||
sec_external_ip_ns="resolver1.opendns.com" | ||
retry_count=30 | ||
|
||
# use dns query to get external ip address | ||
external_ip="$(dig TXT +short o-o.myaddr.l.google.com @${pri_external_ip_ns} | tr -d '"')" | ||
exit_code="${?}" | ||
# remove previous run output file | ||
rm -f /home/nobody/vpn_external_ip.txt | ||
|
||
# if error then try secondary name server | ||
if [[ "${exit_code}" != 0 ]]; then | ||
while true; do | ||
|
||
external_ip="$(dig +short myip.opendns.com @${sec_external_ip_ns})" | ||
external_ip="$(dig TXT +short o-o.myaddr.l.google.com @${pri_external_ip_ns} | tr -d '"')" | ||
exit_code="${?}" | ||
|
||
# if error then try secondary name server | ||
if [[ "${exit_code}" != 0 ]]; then | ||
|
||
external_ip="0.0.0.0" | ||
echo "[warn] Failed to get external IP from Google NS, trying OpenDNS..." | ||
|
||
external_ip="$(dig +short myip.opendns.com @${sec_external_ip_ns})" | ||
exit_code="${?}" | ||
|
||
if [[ "${exit_code}" != 0 ]]; then | ||
|
||
if [ "${retry_count}" -eq "0" ]; then | ||
|
||
external_ip="0.0.0.0" | ||
|
||
echo "[warn] Cannot determine external IP address, exausted retries setting to ${external_ip}" | ||
break | ||
|
||
else | ||
|
||
retry_count=$((retry_count-1)) | ||
sleep 1s | ||
|
||
fi | ||
|
||
else | ||
|
||
echo "[info] Successfully retrieved external IP address ${external_ip}" | ||
break | ||
|
||
fi | ||
|
||
else | ||
|
||
echo "[info] Successfully retrieved external IP address ${external_ip}" | ||
break | ||
|
||
fi | ||
|
||
fi | ||
done | ||
|
||
# write external ip address to text file, this is then read by the downloader script | ||
echo "${external_ip}" > /home/nobody/vpn_external_ip.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters