remove wget dependency, use curl instead

This commit is contained in:
2024-02-29 11:41:25 +01:00
parent ddb6cda6df
commit 64832fc1b1
3 changed files with 21 additions and 23 deletions

View File

@@ -1,16 +1,16 @@
# Snap DynDNS Client
**Snap DynDNS Client** is the perfect counterpart to [**Snap DynDNS Server**](https://src.mehl.mx/mxmehl/snap-dyndns-server). This software can be easily used by any person having an account on such a server instance. This script looks up the current public IP address, sends it to the server part (together with the DynDNS domain name, personal username, and password), which in the end does all the updating process of the domain itself.
**Snap DynDNS Client** is the perfect counterpart to [**Snap DynDNS Server**](https://src.mehl.mx/mxmehl/snap-dyndns-server). This software can be easily used by any person having an account on such a server instance. This script looks up the current public IP address, sends it to the server part (together with the DynDNS domain name, personal username, and password), which in the end does all the updating process of the domain itself.
## Additional Features
The application can also be instructed to ignore certain IP addresses. For those there will be no update sent to the server part. This may make sense if you use a VPN server or tunnel every traffic through Tor. For the latter, it downloads the official list of Tor exit nodes every 7 days and compares your actual public IP with these addresses.
The application can also be instructed to ignore certain IP addresses. For those there will be no update sent to the server part. This may make sense if you use a VPN server or tunnel every traffic through Tor. For the latter, it downloads the official list of Tor exit nodes every 7 days and compares your actual public IP with these addresses.
You can use any service returning your IP address in a plain form (so no HTML headers or other website content). There is one service set by default. Of course, you can also use IPv6 addresses. It just has to correlate with the DynDNS domain's record. Please read more in the server documentation about this.
## Requirements
This Bash script requires curl and wget to be installed. It has been tested on a Debian Sid (April 2016) and doesn't use fancy parameters for both applications.
This Bash script requires curl to be installed. It has been tested on a Debian Bookworm and doesn't use fancy parameters for both applications.
## Installation

View File

@@ -11,18 +11,18 @@ PASS[0]=mypass
#USER[1]=myuser
#PASS[1]=mypass
# Service which shows own IP in plain text (notice that if you use IPv4
# and IPv6 parallely you will get an IPv6 address in many cases in
# return. So you would have to set your DynDNS domain record
# accordingly to AAAA instead of A to make it working. Else, use a
# Service which shows own IP in plain text (notice that if you use IPv4
# and IPv6 parallely you will get an IPv6 address in many cases in
# return. So you would have to set your DynDNS domain record
# accordingly to AAAA instead of A to make it working. Else, use a
# service which only returns your IPv4 address like the default one.)
IPSERV=http://ip4.nandus.net
IPSERV=https://ip4.snapdns.eu
# Timeout for IP requests to the service above in seconds
TIMEOUT=10
# Comma-separated IP(s) which should be ignored.
# If one of these IPs is the current IP, there'll be no DNS update
# Comma-separated IP(s) which should be ignored.
# If one of these IPs is the current IP, there'll be no DNS update
# (e.g. for your VPN servers)
IGNOREIP=127.0.0.1,127.0.0.2

View File

@@ -2,25 +2,25 @@
########################################################################
# Copyright (C) 2016 Max Mehl <mail [at] mehl [dot] mx>
########################################################################
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
########################################################################
#
# Client part of the "Snap DynDNS Server", grabbing public IP address
#
# Client part of the "Snap DynDNS Server", grabbing public IP address
# and pushing it to the server handling the more complicated API stuff
#
#
########################################################################
@@ -55,7 +55,6 @@ function testinst {
fi
}
testinst curl
testinst wget
# Loop over all hosts. $i will be key
for i in "${!USER[@]}"; do
@@ -69,7 +68,7 @@ for i in "${!USER[@]}"; do
# Read old IP, gather new IP via IP return service
OLDIP=$(cat "$oldip")
NEWIP=$(wget -T $TIMEOUT -q -O - $IPSERV)
NEWIP=$(curl -m "$TIMEOUT" -s "$IPSERV")
# Post current timestamp in logfile
echo "[$(date "+%Y-%m-%d %H:%M:%S")]" > "$logfile"
@@ -92,7 +91,7 @@ for i in "${!USER[@]}"; do
if [ ! -e tor-ips.txt ] || [ $[ $(date +%s) - $(stat -L -c %Y tor-ips.txt) ] -gt "604800" ]; then
# download list, extract plain IPs, move back to file
echo "download list"
wget -O tor-ips.txt $EXITNODES
curl "$EXITNODES" > tor-ips.txt
TORIPS=$(grep "^ExitAddress" tor-ips.txt | cut -d" " -f2)
echo $TORIPS | sed 's/ /\n/g' > tor-ips.txt
fi
@@ -106,11 +105,10 @@ for i in "${!USER[@]}"; do
# Run update if old IP and current IP are not equal
if [ ! "$OLDIP" == "$NEWIP" ]; then
echo $NEWIP > "$oldip"
curl -X POST -d "domain=${DOMAIN[$i]}&user=${USER[$i]}&pass=${PASS[$i]}&ip=$NEWIP" "$SERVER" >> "$logfile"
echo "" >> "$logfile"
echo "Updated IP address from $OLDIP to $NEWIP." >> "$logfile"
fi
done