Added auto detection of external ip address
This commit is contained in:
7
TODO
7
TODO
@@ -3,9 +3,6 @@ TODO for dnsupdate
|
|||||||
- Check if address needs update before sending data
|
- Check if address needs update before sending data
|
||||||
- Add a config-file for hostname, domain and password
|
- Add a config-file for hostname, domain and password
|
||||||
All options should be configurable, ttl and force as well.
|
All options should be configurable, ttl and force as well.
|
||||||
- Auto-detect the machine's external ip address'
|
|
||||||
Should work on OS X, Linux and Windows.
|
|
||||||
Should work with multiple interfaces.
|
|
||||||
- Have options to delete a server as well as add/update
|
- Have options to delete a server as well as add/update
|
||||||
- Integrate the relevant dnspython modules
|
- Integrate the relevant dnspython modules
|
||||||
- Add a GUI
|
- Add a GUI
|
||||||
@@ -22,3 +19,7 @@ Done:
|
|||||||
-n hostname
|
-n hostname
|
||||||
-p password
|
-p password
|
||||||
-t ttl
|
-t ttl
|
||||||
|
- Auto-detect the machine's external ip address'
|
||||||
|
Should work on OS X, Linux and Windows.
|
||||||
|
Should work with multiple interfaces.
|
||||||
|
http://www.showmyip.com/simple eller skriva en egen.
|
||||||
|
|||||||
26
dnsupdate.py
26
dnsupdate.py
@@ -6,7 +6,6 @@ import re
|
|||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
# dnsupdate.py
|
# dnsupdate.py
|
||||||
# Updates a dynamic dns-record using a TSIG key.
|
# Updates a dynamic dns-record using a TSIG key.
|
||||||
|
|
||||||
@@ -15,7 +14,17 @@ keyname = "lubcke.se."
|
|||||||
keysecret = "ZGhNJ05b8ThmHOXhJvkvMw=="
|
keysecret = "ZGhNJ05b8ThmHOXhJvkvMw=="
|
||||||
ttl = 60
|
ttl = 60
|
||||||
|
|
||||||
|
def get_ipaddress():
|
||||||
|
# Connects to the dns server to determine which ip address
|
||||||
|
# this host connects from
|
||||||
|
import urllib
|
||||||
|
remote = opener = urllib.FancyURLopener({})
|
||||||
|
f = opener.open("http://www.wahlberg.se/~fredrik/ip.php")
|
||||||
|
ip = f.read().strip()
|
||||||
|
return ip
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# Define option parameters
|
||||||
usage = "usage: %prog [-n] hostname [-i] ip adress [OPTIONS]"
|
usage = "usage: %prog [-n] hostname [-i] ip adress [OPTIONS]"
|
||||||
parser = OptionParser(usage)
|
parser = OptionParser(usage)
|
||||||
parser.add_option("-d", "--domain",
|
parser.add_option("-d", "--domain",
|
||||||
@@ -39,10 +48,14 @@ def main():
|
|||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
global domain, keyname, keysecret, ttl
|
global domain, ipaddress, keyname, keysecret, ttl
|
||||||
|
|
||||||
if options.domain:
|
if options.domain:
|
||||||
domain = options.domain
|
domain = options.domain
|
||||||
|
if options.ipaddress:
|
||||||
|
ipaddress = options.ipaddress
|
||||||
|
else:
|
||||||
|
ipaddress = get_ipaddress()
|
||||||
if options.keyname:
|
if options.keyname:
|
||||||
keyname = options.keyname
|
keyname = options.keyname
|
||||||
if options.password:
|
if options.password:
|
||||||
@@ -50,18 +63,19 @@ def main():
|
|||||||
if options.ttl:
|
if options.ttl:
|
||||||
ttl = options.ttl
|
ttl = options.ttl
|
||||||
|
|
||||||
if not options.ipaddress or not options.name:
|
if not options.name:
|
||||||
print "IP address and hostname are required for operation.\nEnter '%s -h' for usage information" % sys.argv[0]
|
print "A hostname is required for operation.\nEnter '%s -h' for usage information" % sys.argv[0]
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
global hostname, ipaddress
|
global hostname
|
||||||
ipaddress = options.ipaddress
|
|
||||||
hostname = options.name
|
hostname = options.name
|
||||||
|
|
||||||
update()
|
update()
|
||||||
|
|
||||||
|
|
||||||
def update():
|
def update():
|
||||||
|
# The update function connects to the dns server
|
||||||
|
|
||||||
# Sanity check incoming data
|
# Sanity check incoming data
|
||||||
global hostname, ipaddress, ttl
|
global hostname, ipaddress, ttl
|
||||||
hostname = string.replace(hostname, "."+domain, '')
|
hostname = string.replace(hostname, "."+domain, '')
|
||||||
|
|||||||
Reference in New Issue
Block a user