#! /usr/bin/python2.0 # DNSflow 0.1 # a automatic update client for the # dtDNS-Service available from www.dtdns.com # coded end of 2K02 by flowtron@gmx.de # examples : # dnsflow test.dtdns.net opensesame 1.2.3.4 # dnsflow another.name.darktech.org password 101.242.7.42 # dnsflow worm.slyip.org 1!like:it 101.242.42.666 # if your system is anything like mine you can even try omitting the IP, # the script will try to obtain it from the system. # check the lines between following delimiter for system specific information and adapt if needed. # ------------------------------------------------------------------------------------------------ from string import find from sys import argv from httplib import HTTPSConnection,ResponseNotReady from urllib import urlencode from commands import getoutput from re import compile from traceback import print_exc IP="0.0.0.0" PASS="unknown" HOST="unknown" if len(argv)>0: if len(argv)>4:print "ignoring excessive parameters" if len(argv)==4: HOST=argv[1] PASS=argv[2] pattern=compile("(\d{1,3}.){3,3}\d{1,3}") # xxx.xxx.xxx.xxx - IP4 only! # if you need IP6 it shouldn't be a prob' to implement. match=pattern.match(argv[3]) if not match: print "IP information seems corrupt (just IP4 if you don't mind)." HOST="unknown" # for safety reasons no corrupt data will be sent else: #strip pure IP from last argument passed span=match.span() IP=argv[3][span[0]:span[1]] elif len(argv)==3: err=1 # default HOST=argv[1] PASS=argv[2] # ------------------------------------------------------------------------------------------------ IP=getoutput('/sbin/ifconfig | grep -A 1 "ippp0" | grep "inet"') first_colon=find(IP,":") if first_colon!=-1: second_colon=find(IP,":",first_colon+1) if second_colon!=-1: IP=IP[first_colon+1:second_colon] first_space=find(IP," ") if first_space!=-1: IP=IP[:first_space] err=0 # ------------------------------------------------------------------------------------------------ if err==1: print "error determining IP" else: print "updating to >"+str(IP)+"< ..." else: print "usage: dnsflow HOSTNAME PASSWORD (IP)" if HOST!="unknown": params = urlencode({"id" : HOST, "pw" : PASS, "ip" : IP, "client" : "DNSflow 0.1"}) try: conn = HTTPSConnection ("www.dtdns.com") conn.putrequest('POST','/api/autodns.cfm?'+params) conn.endheaders() response=conn.getresponse() print "dtDNS:"+response.read() conn.close() except ResponseNotReady: print "Problems while connecting to dtDNS!" except error,errordata: print "Network problems. ["+str(errordata)+"]" print "Please be sure you are connected to the internet/network." except:# for things like socket.error which I couldn't catch "the usual way"... print "Unexpected error!\nPython traceback:\n" print_exc() else: print "pass them on the command-line." print "\nomitting IP will force the script to try to determine it automatically." print "(note: for this feature the script might need (source) adjustment to fit your system!)"