Last active
December 30, 2024 12:09
-
-
Save imvaskii/c2f8c2cabd2a3991772f108f68dffcde to your computer and use it in GitHub Desktop.
A python (python3) script to update no-ip (https://www.noip.com) dynamic dns ip.
This file contains hidden or 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
#!/usr/bin/env python | |
import requests, socket | |
username = "" | |
password = "" | |
hostname = "" # your domain name hosted in no-ip.com | |
# Gets the current public IP of the host machine. | |
myip = requests.get('http://api.ipify.org').text | |
# Gets the existing dns ip pointing to the hostname. | |
old_ip = socket.gethostbyname(hostname) | |
# Noip API - dynamic DNS update. | |
# https://www.noip.com/integrate/request. | |
def update_dns(config): | |
r = requests.get("http://{}:{}@dynupdate.no-ip.com/nic/update?hostname={}&myip={}".format(*config)) | |
if r.status_code != requests.codes.ok: | |
print(r.content) | |
pass | |
# Update only when ip is different. | |
if myip != old_ip: | |
update_dns( (username, password, hostname, myip) ) | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
setting up above script in crontab.
crontab -e
at the end of the crontab file.
0 0 * * FRI source $WORKON_HOME/no-ip-update/bin/activate && ~/noip-updater/app.py
-> Runs updater script every friday at 00:00.
-> Im activating the virtualenv and then running the script. :)
->
$WORKON_HOME
is a variable provided byvirtualenvwrapper
. I've setup it to~/.virtualenvs