def update_dns(new_ip):
    record_types = ['A', 'AAAA']

    api_url, username, password = get_account_data(True, config_file)
    domain, subdomain, _ = get_domain_update(True, config_file)

    # Instantiate the inwx class (does not connect yet but dispatches calls to domrobot objects with the correct API URL
    inwx_conn = domrobot(api_url, username, password, 'en', False)
    nsentries = inwx_conn.nameserver.info({'domain': domain})

    # Filter entries for subdomain
    records = [record for record in nsentries['record'] if subdomain == record['name']]

    if not records:
	status = "404 Failed"
	return "Subdomain {0} not in list of nameserver entries".format(subdomain), status

    for record in records:
        record_type = record['type']
	if record_type not in record_types:
	    status = "404 Failed"
            return "Unsupported record type: {0}".format(record_type), status
        
	if new_ip != record['content']:
	    try:
	        inwx_conn.nameserver.updateRecord({'id': record['id'], 'content': new_ip, 'ttl': 3600})
    		status = "200 OK"
                return "Updating record {0} from {1} to {2}".format(record['name'], record['content'], new_ip), status
	    except Exception as e:
	        status = "404 Failed"
                return "Failed {0} record of {1} from {2} to {3}::::{4}".format(record_type, record['name'], record['content'], new_ip, e.message), status
	else:
	     status = "200 OK"
             return "Same IP", status
def main():
    api_url, username, password = get_account_data(True)
    domain, subdomain, _ = get_domain_update(True)

    # Instantiate the inwx class (does not connect yet but dispatches calls to domrobot objects with the correct API URL
    inwx_conn = domrobot(api_url, username, password, 'en', False)
    nsentries = inwx_conn.nameserver.info({'domain': domain})

    # Filter entries for subdomain
    nsentries = [
        record for record in nsentries['record'] if subdomain == record['name']
    ]

    assert nsentries, "Subdomain %s not in list of nameserver entries." % subdomain

    # There may be multiple entries for one subdomain, one for each type (A, AAAA, ...)
    for record in nsentries:
        record_type = record['type']  # A, AAAA
        assert record_type in record_type_to_api, "Unsupported record type: %s" % record_type

        new_ip = get_ip(record_type_to_api[record_type])
        if new_ip:
            print "Updating %s record of %s from %s to %s" % (
                record_type, record['name'], record['content'], new_ip)
            inwx_conn.nameserver.updateRecord({
                'id': record['id'],
                'content': new_ip,
                'ttl': 3600
            })
Exemplo n.º 3
0
def main():
    api_url, username, password = get_account_data(True)
    domain, subdomain, _ = get_domain_update(True)

    # Instantiate the inwx class (does not connect yet but dispatches calls to domrobot objects with the correct API URL
    inwx_conn = domrobot(api_url, username, password, "en", False)
    nsentries = inwx_conn.nameserver.info({"domain": domain})

    # Filter entries for subdomain
    nsentries = [record for record in nsentries["record"] if subdomain == record["name"]]

    assert nsentries, "Subdomain %s not in list of nameserver entries." % subdomain

    # There may be multiple entries for one subdomain, one for each type (A, AAAA, ...)
    for record in nsentries:
        record_type = record["type"]  # A, AAAA
        assert record_type in record_type_to_api, "Unsupported record type: %s" % record_type

        new_ip = get_ip(record_type_to_api[record_type])
        if new_ip:
            print "Updating %s record of %s from %s to %s" % (record_type, record["name"], record["content"], new_ip)
            inwx_conn.nameserver.updateRecord({"id": record["id"], "content": new_ip, "ttl": 3600})
def main():
    api_url, username, password = get_account_data(True)
    domain, subdomain, default_ip = get_domain_update(True)
    try:
        new_ip = urlopen(IPV6_DETECTION_API).read().decode('ascii')
    except:
        # If something failed with the IPv6 detection, we may abort at this point
        return
        # or simply set the default value:
        new_ip = default_ip
    # Instantiate the inwx class (does not connect yet but dispatches calls to domrobot objects with the correct API URL
    inwx_conn = domrobot(api_url, username, password, 'en', False)
    # get all the nameserver entries for a certain domain 
    nsentries = inwx_conn.nameserver.info({'domain': domain})
    for record in nsentries['record']:
        if subdomain == record['name']:
            id = record['id']
            break
    if id:
        print "Setting subdomain %s to the new IPv6 IP %s." % (subdomain, new_ip)
        inwx_conn.nameserver.updateRecord({'id':id,'content':new_ip,'ttl':3600})
    else:
        print "Subdomain not in list of nameserver entries."
Exemplo n.º 5
0
#
# You should have received a copy of the GNU General Public License
# along with inwx-dyndns. If not, see <http://www.gnu.org/licenses/>.

# This is obviously heavily borrowed (almost everything is the same) from Philipp Klaus' python-inwx-xmlrpc.

import os
import time
from inwx import domrobot
from configuration import get_account_data, get_domain_update

MINUTES = 15

while True:
    api_url, username, password = get_account_data(True)
    domain, subdomain, default_ip = get_domain_update(True)
    with open(os.environ.get("IPv4_PATH")) as f:
        new_ip = f.read()

    inwx_conn = domrobot(api_url, username, password, "en", False)
    nsentries = inwx_conn.nameserver.info({"domain": domain})
    ids = []
    for record in nsentries["record"]:
        if record["name"] in ["", "*"]:
            ids.append(record["id"])
    for id_ in ids:
        print("Setting subdomain %s to the new IPv4 IP %s." % (subdomain, new_ip))
        inwx_conn.nameserver.updateRecord({"id": id_, "content": new_ip, "ttl": 3600})
    print(f"Going to sleep for {MINUTES} minutes")
    time.sleep(MINUTES * 60)