Last active
August 29, 2015 14:11
-
-
Save rochacon/e15e05bc17f071e43d92 to your computer and use it in GitHub Desktop.
Simple script to set DNS for local IP
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 | |
# | |
# This is a simple script to set the local IP to an Route53 zone | |
# | |
# Dependencies: | |
# pip install boto netifaces | |
# | |
# Usage: | |
# host-ip-to-route53.py wlan1 machine1.domain.net | |
# | |
import boto | |
import netifaces | |
import socket | |
import sys | |
def update_a(host, ip): | |
r53 = boto.connect_route53() | |
zone = r53.get_zone('.'.join(h.split('.')[-2:])) | |
try: | |
zone.update_a(host, ip, ttl=60) | |
except: # where only brave man stands | |
zone.add_a(host, ip, ttl=60) | |
def main(iface, host): | |
ip = netifaces.ifaddresses(iface)[2][0]['addr'] | |
if socket.gethostbyname(host) != ip: | |
print('Updating %s with %s' % (host, ip)) | |
update_a(host, ip) | |
else: | |
print('Host matches') | |
if __name__ == '__main__': | |
iface = sys.argv[1] | |
host = sys.argv[2] | |
main(iface, host) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment