Skip to content

Instantly share code, notes, and snippets.

@RC1140
Last active October 8, 2015 07:29
Show Gist options
  • Select an option

  • Save RC1140/3299314 to your computer and use it in GitHub Desktop.

Select an option

Save RC1140/3299314 to your computer and use it in GitHub Desktop.

Revisions

  1. RC1140 revised this gist Sep 27, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion DynamicDNS.py
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@
    aws_secret_access_key=secret_key,
    )

    zone = conn.get_hosted_zone_by_id()
    zone = conn.get_hosted_zone_by_id(hostedZoneID)
    #Find the recordset we are looking for and store it
    recset = None
    for record_set in zone.record_sets:
  2. RC1140 revised this gist Sep 25, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion DynamicDNS.py
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,13 @@
    import socket
    import route53

    domainName = ''
    domainName = ''#Make sure this is a FQDN i.e. it should have a '.' at the end.
    access_id = ''
    secret_key = ''
    hostedZoneID = '' #Get this from your aws account

    try:
    #This can be changed to look at the aws record if you dont want to make a socket call to the machine.
    oldIP = socket.gethostbyname(domainName)
    except:
    oldIP = 'Not found'
  3. RC1140 revised this gist Sep 25, 2013. 1 changed file with 26 additions and 16 deletions.
    42 changes: 26 additions & 16 deletions DynamicDNS.py
    Original file line number Diff line number Diff line change
    @@ -1,29 +1,39 @@
    #!/usr/bin/env python
    import stun
    import socket
    import boto
    from cirrus.r53 import Zone
    import route53

    domainName = ''
    access_id = ''
    access_id = ''
    secret_key = ''
    hostedZoneID = '' #Get this from your aws account

    try:
    oldIP = socket.gethostbyname(domainName)
    except:
    oldIP = 'Not found'

    nat_type, current_ip, external_port = stun.get_ip_info()

    conn = route53.connect(
    aws_access_key_id=access_id,
    aws_secret_access_key=secret_key,
    )

    zone = conn.get_hosted_zone_by_id()
    #Find the recordset we are looking for and store it
    recset = None
    for record_set in zone.record_sets:
    if record_set.name == domainName:
    recset = record_set
    break

    #if the IP has changed save it
    if oldIP.__str__() != current_ip.__str__():
    print 'IPs do not match : '
    print 'Old : 'oldIP.__str__()
    print 'Current : 'current_ip.__str__()
    conn = boto.connect_route53(access_id,secret_key)
    r53zone = Zone(conn, domainName)
    rtype = 'A'
    existing = r53zone.get_host(domainName)
    r53zone.update_host(domainName, rtype, None, existing, current_ip.__str__())
    print 'Zone Updated'
    else:
    print 'IPs are still the same'
    print 'Old : 'oldIP.__str__()
    print 'Current : 'current_ip.__str__()
    #Print the old and current IP for logging purposes
    print oldIP.__str__()
    print current_ip.__str__()
    #Overwrite the existing records , this should always be a single IP as string
    recset.records = [current_ip.__str__()]
    recset.save()
    print 'updated recset'
  4. Jameel Haffejee created this gist Aug 8, 2012.
    29 changes: 29 additions & 0 deletions DynamicDNS.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/usr/bin/env python
    import stun
    import socket
    import boto
    from cirrus.r53 import Zone

    domainName = ''
    access_id = ''
    secret_key = ''

    try:
    oldIP = socket.gethostbyname(domainName)
    except:
    oldIP = 'Not found'
    nat_type, current_ip, external_port = stun.get_ip_info()
    if oldIP.__str__() != current_ip.__str__():
    print 'IPs do not match : '
    print 'Old : 'oldIP.__str__()
    print 'Current : 'current_ip.__str__()
    conn = boto.connect_route53(access_id,secret_key)
    r53zone = Zone(conn, domainName)
    rtype = 'A'
    existing = r53zone.get_host(domainName)
    r53zone.update_host(domainName, rtype, None, existing, current_ip.__str__())
    print 'Zone Updated'
    else:
    print 'IPs are still the same'
    print 'Old : 'oldIP.__str__()
    print 'Current : 'current_ip.__str__()