Auto update IP address via Post Query for Dynamic DNS Services UNIX

This script is suitable for all systems based on Linux or UNIX-like operating systems. The main functions are getting an IP address from an external server. Then address compared with the current host address. If the address is different, a POST request is made to the DNS server.

 

For *nix based OS (Linux, Mac OS, other UNIX): You need to have curl, wget, jq installed.

We are use 3 files: ip.sh

#!/bin/sh
a="do.sh"
old_ip="`while read LINE; do echo "$LINE" | cut -f1 -d":"; done < ip.txt`" new_ip="`wget -q -O - your-ip-check-script.net/ip.php`"
echo ${old_ip}
echo ${new_ip}
if [ "$old_ip" != "$new_ip" ]
then
sh do.sh
else
echo "Do nothing"
fi

do.sh

See also  How to convert Thick vmdk to Thin and export to OVF/OVA ESXI virtual machine?

#!/bin/sh
old_ip="`while read LINE; do echo "$LINE" | cut -f1 -d":"; done < ip.txt`" new_ip="`wget -q -O - your-ip-check-script.net/ip.php`"
echo ${old_ip}
echo ${new_ip}
curl -X POST http://ddns-service-net.com:5000 -d "{\"ip_adress\": \"`wget -q -O - your-ip-check-script.net/ip.php`\", \"domain_name\": \"google.com\" }"
cp /dev/null ip.txt
echo ${new_ip} >> ip.txt

ip.txt with random start ip content
1.2.3.4

Add the ip.sh file for execution to CRON. Set the launch frequency “every 30 seconds” crontab -e
* * * * * /bin/sh -l -c “/path/to/ip.sh; sleep 30 ; /path/to/ip.sh ”

Don’t forget install wget: sudo apt install wget

Author: admin

Leave a Reply

Your email address will not be published. Required fields are marked *