Esempio n. 1
0
def test_can_update_dns_record():
    global client
    if client is None:
        client = GoDaddyClient()
    domain = account['test_domain']
    prefix = 'test{}'.format(random.randint(10000, 99999))
    addr = '{}.{}.{}.{}'.format(random.randint(10, 20), random.randint(10, 20),
                                random.randint(10, 20), random.randint(10, 20))
    addr2 = '{}.{}.{}.{}'.format(random.randint(20, 30), random.randint(20, 30), \
                                random.randint(20, 30), random.randint(20, 30))
    # can create new record
    assert client.update_dns_record(prefix + '.' + domain,
                                    addr), 'Create DNS Failed'
    for record in client.find_dns_records(domain):
        if record.hostname == prefix:
            assert record.value == addr, 'DNS Record Doesnot Match Addr {}'.format(
                addr)
            break
    else:
        raise ValueError('DNS Record Cannot Created')

    # can update previous record
    assert client.update_dns_record(prefix + '.' + domain,
                                    addr2), 'Update DNS Failed'
    for record in client.find_dns_records(domain):
        if record.hostname == prefix:
            assert record.value == addr2, 'DNS Record Doesnot Match Addr2 {}'.format(
                addr2)
            break

    # can delete dns record
    assert client.delete_dns_record(prefix + '.' + domain), 'Delete DNS Failed'
    for record in client.find_dns_records(domain):
        if record.hostname == prefix:
            raise ValueError('DNS Record still exists')
Esempio n. 2
0
    def __init__(self, configfile):

        self.__godaddyclient = GoDaddyClient()

        # read config
        self.__configparser = ConfigParser()
        self.__configparser.read(configfile)
        self.__updatemessage = ''
        self.__username = self.__configparser.get('global', 'username')
        self.__password = self.__configparser.get('global', 'password')
        self.__logfile = self.__configparser.get('global', 'logfile')
        self.__changedetected = False
        self.__domains = []
        for section in self.__configparser.sections():
            if section != 'global':
                self.__domains.append(section)

        # mail config
        self.__mailnotifyenabled = self.__configparser.get('global', 'mail_notify_enabled')
        self.__mailreceiver = self.__configparser.get('global', 'mail_receiver')
        self.__mailsender = self.__configparser.get('global', 'mail_sender')
        self.__mailuser = self.__configparser.get('global', 'smtp_user')
        self.__mailpassword = self.__configparser.get('global', 'smtp_password')
        self.__smtphost = self.__configparser.get('global', 'smtp_host')
        self.__smtpport = self.__configparser.get('global', 'smtp_port')
Esempio n. 3
0
def godaddycli(username, password, cfg):
    client = GoDaddyClient()
    c = client.login(username, password)
    if not c:
        print "couldn't login"
        sys.exit(1)

    if cfg.delete is not None:
        godaddycli_delete(client, cfg)
        return 0
    if cfg.update is not None:
        godaddycli_update(client, cfg)
        return 0
    if cfg.list is not None:
        godaddycli_list(client, cfg)
        return 0
Esempio n. 4
0
def godaddycli(username, password, cfg):
    client = GoDaddyClient()
    c = client.login(username, password)
    if not c:
            print "couldn't login"
            sys.exit(1)

    if cfg.delete is not None:
        godaddycli_delete(client, cfg)
        return 0
    if cfg.update is not None:
        godaddycli_update(client, cfg)
        return 0
    if cfg.list is not None:
        godaddycli_list(client, cfg)
        return 0
Esempio n. 5
0
def test_can_update_dns_record():
    global client
    if client is None:
        client = GoDaddyClient()
    domain = account['test_domain']
    prefix = 'test{}'.format(random.randint(10000, 99999))
    addr = '{}.{}.{}.{}'.format(random.randint(10, 20), random.randint(10, 20),
                                random.randint(10, 20), random.randint(10, 20))
    addr2 = '{}.{}.{}.{}'.format(random.randint(20, 30), random.randint(20, 30), \
                                random.randint(20, 30), random.randint(20, 30))
    # can create new record
    assert client.update_dns_record(prefix+'.'+domain, addr), 'Create DNS Failed'
    for record in client.find_dns_records(domain):
        if record.hostname == prefix:
            assert record.value == addr, 'DNS Record Doesnot Match Addr {}'.format(addr)
            break
    else:
        raise ValueError('DNS Record Cannot Created')

    # can update previous record
    assert client.update_dns_record(prefix+'.'+domain, addr2), 'Update DNS Failed'
    for record in client.find_dns_records(domain):
        if record.hostname == prefix:
            assert record.value == addr2, 'DNS Record Doesnot Match Addr2 {}'.format(addr2)
            break

    # can delete dns record
    assert client.delete_dns_record(prefix+'.'+domain), 'Delete DNS Failed'
    for record in client.find_dns_records(domain):
        if record.hostname == prefix:
            raise ValueError('DNS Record still exists')
for domain in domains:
    realdomain = domain
    if realdomain.startswith("@."):
        realdomain = realdomain[2:]
    dom_ip = socket.gethostbyname(realdomain)
    if wan_ip != dom_ip:
        print '----------------------------------------------------'
        print 'GoDaddy A Record Update | ' + realdomain + ' (' + domain + ') | ' + time.strftime(
            "%a %d %B %I:%M %p")
        print 'WAN IP:\t\t' + wan_ip
        print 'Domain IP:\t' + dom_ip
        print 'IPs don\'t match, checking if already updated...'
        old_ip = '0'
        if os.path.isfile("/usr/local/etc/old_ips/" + realdomain):
            oipf = open("/usr/local/etc/old_ips/" + realdomain)
            old_ip = oipf.read()
            print 'Old IP:\t\t' + old_ip
        if wan_ip != old_ip:
            print 'Updating A Record...'
            client = GoDaddyClient()
            if client.login(username, password):
                client.update_dns_record(domain, wan_ip)
                nipf = open("/usr/local/etc/old_ips/" + realdomain, 'w+')
                nipf.write(wan_ip)
                nipf.close()
                print 'DNS has been updated.'
            else:
                print 'Failed to login, please check \'update-dns.py\''
        else:
            print 'Already updated, dns not flushed.'
for domain in domains:
	realdomain = domain
	if realdomain.startswith("@."):
		realdomain = realdomain[2:]
	dom_ip = socket.gethostbyname(realdomain)
	if wan_ip != dom_ip:
		print '----------------------------------------------------'
		print 'GoDaddy A Record Update | ' + realdomain  + ' (' + domain + ') | ' + time.strftime("%a %d %B %I:%M %p")
		print 'WAN IP:\t\t' + wan_ip
		print 'Domain IP:\t' + dom_ip
		print 'IPs don\'t match, checking if already updated...'
		old_ip = '0'
		if os.path.isfile("/usr/local/etc/old_ips/" + realdomain):
			oipf = open("/usr/local/etc/old_ips/" + realdomain)
			old_ip = oipf.read()
			print 'Old IP:\t\t' + old_ip
		if wan_ip != old_ip:
			print 'Updating A Record...'
			client = GoDaddyClient()
			if client.login(username, password):
				client.update_dns_record(domain, wan_ip)
				nipf = open("/usr/local/etc/old_ips/" + realdomain, 'w+')
				nipf.write(wan_ip)
				nipf.close()
				print 'DNS has been updated.'
			else:
				print 'Failed to login, please check \'update-dns.py\''
		else:	
			print 'Already updated, dns not flushed.'	
Esempio n. 8
0
def test_can_find_target_domain():
    global client
    if client is None:
        client = GoDaddyClient()
    assert account['test_domain'] in client.find_domains(), 'domain not found'
Esempio n. 9
0
from pygodaddy import GoDaddyClient
import requests
import time 

while True:
	client = GoDaddyClient()

	ip = requests.get('http://canihazip.com/s').text

	with open( 'last_ip.dat', 'w+' ) as last_ip:
		if( last_ip != ip ):
			f = open( 'last_ip.dat', 'w' )
			f.write( ip )
			f.close()

			username='******'
			password='******'

			if client.login( username, password ):
				client.update_dns_record( 'your.dns.record', ip )
	
	time.sleep(300)
Esempio n. 10
0
#command line arguments parsing
parser = argparse.ArgumentParser('A Python script to do updates to a GoDaddy DNS host A record')
parser.add_argument('-v', '--verbose', action='store_true', help="send emails on 'no ip update required'")
args = parser.parse_args()

#start log file
logging.basicConfig(filename=godaddy.logfile, format='%(asctime)s %(message)s', level=logging.INFO)

#what is my public ip?
public_ip = pif.get_public_ip()
logging.info("My ip: {0}".format(public_ip))

# login to GoDaddy DNS management
# docs at https://pygodaddy.readthedocs.org/en/latest/
client = GoDaddyClient()

if client.login(godaddy.gduser, godaddy.gdpass):
	# find out current dns record value. This can also be done with a quick nslookupA
	# with something like socket.gethostbyname()
	# however, this can include caching somewhere in the dns layers
	# We could also use dnspython libraray, but that adds a lot of complexity

	# use the GoDaddy object to find our current IP registered
	domaininfo = client.find_dns_records(godaddy.domain)
	for record in domaininfo:
		if record.hostname == godaddy.host:
			if record.value != public_ip:
				logging.info("Update required: old {0}, new {1}".format(record.value, public_ip))
				updateinfo = "old " + record.value + ", new " + public_ip
				# This will fail if you try to set the same IP as already registered!
Esempio n. 11
0
def test_can_find_target_domain():
    global client
    if client is None:
        client = GoDaddyClient()
    assert account['test_domain'] in client.find_domains(), 'domain not found'
Esempio n. 12
0
def test_login():
    global client
    if client is None:
        client = GoDaddyClient()
    assert client.login(account['username'],
                        account['password']), 'Login Failed'
Esempio n. 13
0
from pygodaddy import GoDaddyClient
import sys

username = sys.argv[1]
password = sys.argv[2]

client = GoDaddyClient()
if client.login(username, password):
    print client.find_domains()
    client.update_dns_record('{{ item }}', '{{ inventory_hostname }}')
from pygodaddy import GoDaddyClient
import pif
import logging

logging.basicConfig(filename='/path/to/file.log', \
    format='%(asctime)s %(message)s', level=logging.INFO)
    
GODADDY_USERNAME="******"
GODADDY_PASSWORD="******"
client = GoDaddyClient()

domain = 'domain'
public_ip = pif.get_public_ip()

# this file contains current ip address of your server
ip_file_value = open('/path/to/ip_file', 'r').read()

if ip_file_value == public_ip:
    exit(0)
else:
    if client.login(GODADDY_USERNAME, GODADDY_PASSWORD):
        hostnames = []
        
        # update IP for every A record
        for i in range(len(client.find_dns_records(domain))):        
            hostnames.append(client.find_dns_records(domain)[i].hostname)
            client.update_dns_record(hostnames[i]+"."+domain, public_ip)
        
        logging.info("Success! IP = '{0}'".format(public_ip))
        
        # write a new IP to file
Esempio n. 15
0
from pygodaddy import GoDaddyClient

username = "******"
password = "******"

if len(sys.argv) <= 1:
    print("Usage: " + sys.argv[0] + "hostname [ip]")
    sys.exit(1);

hostname = sys.argv[1]

print(hostname)
if len(sys.argv) == 2:
    sys.stdout.write("Get IP...")
    sys.stdout.flush()
    ip = urllib2.urlopen('http://ip.42.pl/raw').read()
if len(sys.argv) == 3:
    ip = sys.argv[2]

print(ip)

client = GoDaddyClient()

print("Logging into GoDaddy...")
if client.login(username, password):
    print("Updating IP...")
    if client.update_dns_record(hostname, ip):
        print("Update OK!")
    else:
        print("Update fail!")
Esempio n. 16
0
class GodaddyDnsUpdater:
    @property
    def __publicip(self):
        return get('https://api.ipify.org').text

    @property
    def __isfullymanaged(self):
        if self.__configparser.get('global', 'fully_managed').lower() == 'yes':
            return True
        else:
            return False

    @property
    def __usetls(self):
        if self.__configparser.get('global', 'smtp_tls').lower() == 'yes':
            return True
        else:
            return False

    def __init__(self, configfile):

        self.__godaddyclient = GoDaddyClient()

        # read config
        self.__configparser = ConfigParser()
        self.__configparser.read(configfile)
        self.__updatemessage = ''
        self.__username = self.__configparser.get('global', 'username')
        self.__password = self.__configparser.get('global', 'password')
        self.__logfile = self.__configparser.get('global', 'logfile')
        self.__changedetected = False
        self.__domains = []
        for section in self.__configparser.sections():
            if section != 'global':
                self.__domains.append(section)

        # mail config
        self.__mailnotifyenabled = self.__configparser.get('global', 'mail_notify_enabled')
        self.__mailreceiver = self.__configparser.get('global', 'mail_receiver')
        self.__mailsender = self.__configparser.get('global', 'mail_sender')
        self.__mailuser = self.__configparser.get('global', 'smtp_user')
        self.__mailpassword = self.__configparser.get('global', 'smtp_password')
        self.__smtphost = self.__configparser.get('global', 'smtp_host')
        self.__smtpport = self.__configparser.get('global', 'smtp_port')

    def updatedns(self):
        self.__login()
        for domain in self.__domains:
            self.__update(domain)
        if self.__mailnotifyenabled and self.__changedetected:
            self.__mailnotify(self.__updatemessage)

    def __update(self, domain):
        hostnames = [hostname.strip() for hostname in self.__configparser.get(domain, 'hostnames').split(',')]
        godaddyhostnames = [host[1] for host in self.__godaddyclient.find_dns_records(domain)]

        # update listed hostnames
        for hostname in hostnames:
            if hostname in godaddyhostnames:
                if self.__godaddyclient.update_dns_record(hostname + '.' + domain, self.__publicip):
                    print(hostname + '.' + domain + ' updated.')
                    self.__changedetected = True
                    self.__updatemessage = self.__updatemessage + hostname + '.' + domain + ' updated. \n'
            else:
                if self.__isfullymanaged:
                    if self.__godaddyclient.update_dns_record(hostname + '.' + domain, self.__publicip):
                        print(hostname + '.' + domain + ' added.')
                        self.__changedetected = True
                        self.__updatemessage = self.__updatemessage + hostname + '.' + domain + ' added. \n'

        # delete not listed hostnames
        godaddyhostnames = [host[1] for host in self.__godaddyclient.find_dns_records(domain)]
        if self.__isfullymanaged:
            for godaddyhostname in godaddyhostnames:
                if godaddyhostname not in hostnames:
                    if self.__godaddyclient.delete_dns_record(godaddyhostname + '.' + domain):
                        print(godaddyhostname + '.' + domain + ' deleted.')
                        self.__changedetected = True
                        self.__updatemessage = self.__updatemessage + godaddyhostname + '.' + domain + ' deleted. \n'

    def __login(self):
        if not self.__godaddyclient.is_loggedin():
            self.__godaddyclient.login(self.__username, self.__password)

    def __mailnotify(self, message):
        smtpserver = SMTP(self.__smtphost, self.__smtpport)
        header = 'To:' + self.__mailreceiver + '\n' + 'From: ' + self.__mailsender + '\n' + 'Subject:Godaddy dns updater \n'
        msg = header + '\n' + 'Public ip: ' + self.__publicip + '\n\n' + message + '\n\n'
        try:
            if self.__usetls:
                smtpserver.starttls()
            smtpserver.login(self.__mailuser, self.__mailpassword)
            smtpserver.sendmail(self.__mailsender, self.__mailreceiver, msg)
            print('mail notify sent.')
        except:
            print('mail notify failed service failed!')
        finally:
            smtpserver.close()
Esempio n. 17
0
#!/usr/bin/env python
 
import logging
import pif
from pygodaddy import GoDaddyClient
 
logging.basicConfig(filename='godaddy.log', format='%(asctime)s %(message)s', level=logging.INFO)
GODADDY_USERNAME="******";
GODADDY_PASSWORD="******";
client = GoDaddyClient()
client.login(GODADDY_USERNAME, GODADDY_PASSWORD)


logging.info(client.find_domains())

for domain in client.find_domains():
    dns_records = client.find_dns_records(domain)
    public_ip = pif.get_public_ip()
    logging.debug("Domain '{0}' DNS records: {1}".format(domain, dns_records))
    if public_ip != dns_records[0].value:
        client.update_dns_record(domain, public_ip)
        logging.info("Domain '{0}' public IP set to '{1}'".format(domain, public_ip))
Esempio n. 18
0
def test_login():
    global client
    if client is None:
        client = GoDaddyClient()
    assert client.login(account['username'], account['password']), 'Login Failed'