Mass change of IPs on Linode DNS

Is it possible using the API?

Has anyone made a script or anything already?

1 Reply

Yup, that's one of the many things the API is useful for.

Here's a quick and dirty script I used the last time I did it:

#!/usr/bin/python

import api

instance = api.Api(key='yourkeyhere')

for domain in instance.domain_list():
    if domain['TYPE'] == 'master':
        print("Updating %s (%i)..." % (domain['DOMAIN'], domain['DOMAINID']))
        for resource in instance.domain_resource_list(domainid=domain['DOMAINID']):
            if resource['TYPE'] == 'AAAA' and resource['TARGET'] == '2001:470:1f06:f41::2':
                print('Old AAAA Record Found: %s.%s (%i)' % (resource['NAME'], domain['DOMAIN'], resource['RESOURCEID']))
                newresid = instance.domain_resource_create(domainid=domain['DOMAINID'], type='AAAA', name=resource['NAME'], target='2001:470:1f07:f41::dead:beef')
                print('  Created resource %i' % newresid['ResourceID'])
                oldresid = instance.domain_resource_delete(domainid=domain['DOMAINID'], resourceid=resource['RESOURCEID'])
                print('  Deleted resource %i' % oldresid['ResourceID'])
            elif resource['TYPE'] == 'A' and resource['TARGET'] == '67.18.176.246':
                print('Old A Record Found: %s.%s (%i)' % (resource['NAME'], domain['DOMAIN'], resource['RESOURCEID']))
                newresid = instance.domain_resource_create(domainid=domain['DOMAINID'], type='A', name=resource['NAME'], target='97.107.134.213')
                print('  Created resource %i' % newresid['ResourceID'])
                oldresid = instance.domain_resource_delete(domainid=domain['DOMAINID'], resourceid=resource['RESOURCEID'])
                print('  Deleted resource %i' % oldresid['ResourceID'])

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct