-
-
Save raaghulr/42f6871169cfec42d1aa224069325090 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
test