Last active
October 8, 2015 07:29
-
-
Save RC1140/3299314 to your computer and use it in GitHub Desktop.
DynamicDNS For Use With AmazonRoute53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import stun | |
| import socket | |
| import route53 | |
| domainName = '' | |
| 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 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' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are unable to install pytz because of issues with pip , add the following to a file called requirements.txt
"pytz>=2013b"
and then install with with , pip install -r requirements.txt