Ejemplo n.º 1
0
def dnsupdater(fqdn, ipaddr):
    """ This updates the DNS name providing fqdn and IP """
    from area53 import route53
    # A bit hacky, here I choose which domain I need to search, in this case I use subdomains
    domain = '.'.join(fqdn.split('.')[-3:])
    zone = route53.get_zone(domain)
    arec = zone.get_a(fqdn)

    if arec:
        old_value = arec.resource_records[0]
        if old_value == ipaddr:
            print '%s is current. (%s)' % (fqdn, ipaddr)
            return True

        print 'Updating %s: %s -> %s' % (fqdn, old_value, ipaddr)

        try:
            zone.update_a(fqdn, ipaddr, 900)

        except DNSServerError:
            # This can happen if the record did not already exist. Let's
            # try to add_a in case that's the case here.
            zone.add_a(fqdn, ipaddr, 900)
    else:
        print 'Adding %s:%s' % (fqdn, ipaddr)
        zone.add_a(fqdn, ipaddr, 900)
Ejemplo n.º 2
0
    def get_dns(self, config):
        # Lazy load, route53 has some questionable reliance on env variables
        os.environ["AWS_SECRET_ACCCES_KEY"] = config["secret-access-key"]
        os.environ["AWS_ACCESS_KEY_ID"] = config["access-key-id"]

        from area53 import route53

        dns = route53.get_zone(config["zone"])
        if dns is None:
            raise InvalidConfig("Invalid zone %s, use domain name" % config["zone"])
        return dns
Ejemplo n.º 3
0
def main():
    sub_domain = 'home'
    domain = 'tylercipriani.com'
    fqdn = '%s.%s' % (sub_domain, domain)

    zone = route53.get_zone(domain)
    a_rec = zone.get_a(fqdn)
    new_ip = get_ip()

    if (a_rec):
        if new_ip == a_rec.resource_records[0]:
            print '%s is current. (%s)' % (fqdn, new_ip)
            sys.exit(0)

        try:
            zone.update_a(fqdn, new_ip, 900)
        except DNSServerError:
            zone.add_a(fqdn, new_ip, 900)

    else:
        zone.add_a(fqdn, new_ip, 900)
Ejemplo n.º 4
0
    def set_zone_ip(self,name,ip_address):
        """
        Set the zone ip address given the zone
        """

        self.log("Setting the zone IP")

        from area53 import route53

        self.log("Getting the zone for %s" % name)

        try:
            zone = route53.get_zone(name)
        except Exception as e:
            self.log("Problem getting zone - %s" % e.message)
            raise

        if not zone:
            self.log("Zone not found")
            return

        try:
            record_to_update = zone.get_a(name)
        except Exception as e:
            self.log("Problem getting A record - %s" % e.message)
            raise

        if record_to_update and zone:
            try:
                zone.update_a(record_to_update.name,ip_address,record_to_update.ttl)
            except Exception as e:
                self.log("Problem updating zone record - %s" % e.message)
                raise
            self.log("Update performed")

        return
Ejemplo n.º 5
0
Archivo: test.py Proyecto: LucsT/Area53
 def setUpClass(self):
     zone = route53.get_zone('example.com')
     if zone is not None:
         zone.delete()
     self.zone = route53.create_zone('example.com')
Ejemplo n.º 6
0
if options.verbose :
    logging.basicConfig(
                        level=logging.INFO,
                        )

content=urlopen(options.ip_get_url).read().strip()
ip_list=re.findall( r'[0-9]+(?:\.[0-9]+){3}',content)
if len(ip_list) < 1:
    logging.error("Unable to find an IP address from within the URL:  %s" % options.ip_get_url)
    sys.exit(-1)
current_ip=ip_list[0]
record_to_update=options.record_to_update
zone_to_update='.'.join(record_to_update.split('.')[-2:])

try:
    socket.inet_aton(current_ip)
    zone = route53.get_zone(zone_to_update)
    for record in zone.get_records():
        if search(r'<Record:A:' + record_to_update, str(record)) :
            if current_ip in record.to_print() :
                logging.info('Record IP matches, doing nothing.')
                sys.exit()
            logging.info('IP does not match, update needed.')
            zone.delete_a(record_to_update)
            zone.add_a(record_to_update, current_ip)
            sys.exit()
    logging.info('Record not found, add needed')
    zone.add_a(record_to_update, current_ip)
except socket.error:
    logging.info('Invalid IP format obtained from URL (' + current_ip + ')')
Ejemplo n.º 7
0
 def setUp(self):
     from area53 import route53
     self.dns = route53.get_zone(os.environ['AWS_ROUTE53_ZONE'])
Ejemplo n.º 8
0
 def setUpClass(self):
     zone = route53.get_zone('example.com')
     if zone is not None:
         zone.delete()
     self.zone = route53.create_zone('example.com')
Ejemplo n.º 9
0
import sys
from datetime import datetime

# Modified from https://markcaudill.me/blog/2012/07/dynamic-route53-dns-updating-with-python/

domain = 'domain.tld'
subdomain = 'subdomain_name'


def get_public_ip():
    r = requests.get('http://icanhazip.com')
    return r.text.rstrip()


fqdn = '%s.%s' % (subdomain, domain)
zone = route53.get_zone(domain)
arec = zone.get_a(fqdn)
new_value = get_public_ip()
datestr = '"Last update %s."' % datetime.utcnow().strftime('%Y-%m-%d %H:%M')

if arec:
    old_value = arec.resource_records[0]

    if old_value == new_value:
        print '%s is current. (%s)' % (fqdn, new_value)
        sys.exit(0)

    print 'Updating %s: %s -> %s' % (fqdn, old_value, new_value)

    try:
        zone.update_a(fqdn, new_value, 900)
Ejemplo n.º 10
0
    for l in lines:
        m = re.search('^\s+PP IP Address Local: (\d+\.\d+\.\d+\.\d+),', l)
        if m:
            r['ip'] = m.group(1)
    return r


def get_current_ipaddr(host, passwd):
    cmd = './rtx1x00_show_status_pp_1.exp %s %s' % (host, passwd)
    r = run_expect(cmd)

    return r['ip']

# FIXME: Update with your own parameters.
ip = get_current_ipaddr('192.168.x.254', 'password')
zone = route53.get_zone('example.jp')
a_record = zone.get_a('hoge.example.jp')

old_ip = a_record.resource_records[0]
if old_ip == ip:
    sys.exit(0)

print('IP %s -> %s' % (old_ip, ip))
zone.update_a('hoge.example.jp', ip, 900)

try:
    import slackweb
except:
    sys.exit(0)

# FIXME: Update with your own parameters.