#!/usr/bin/python
import ConfigParser
import urllib2
import requests

# Config File Read
cfg = ConfigParser.ConfigParser()
cfg.read("./config.conf")

# Host settings
remoteHost = cfg.get("REMOTE","ping")
remoteMail = cfg.get("REMOTE","mail")
toAddress = cfg.get("REMOTE","to")

# Dyndns settings
dyndnsUsername = cfg.get("DYNDNS", "user")
dyndnsPassword = cfg.get("DYNDNS", "password")
dyndnsHostname = cfg.get("DYNDNS", "hostname")

# Local parameters
mode = cfg.get("LOCAL", "mode")

# Get new IP from remote and old IP from local
ip = urllib2.urlopen(remoteHost).read().strip("\n")
f = open("ip","r+")
oldIP = f.read()
f.close()

# Compare IP s and process
if ip != oldIP:
	f = open("ip","w+")
	f.write(ip)
	f.close()
	url = "http://"+dyndnsUsername+":"+dyndnsPassword+"@members.dyndns.org/nic/update?hostname="+dyndnsHostname+"&myip="+ip+"&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
	if(mode == "MAIL"):
		urllib2.urlopen(remoteMail+"?to="+toAddress)
	elif(mode == "DYNDNS"):
		retCode = requests.get(url)
	elif(mode == "BOTH"):
                retCode = requests.get(url)
		urllib2.urlopen(remoteMail+"?to="+toAddress)
	else:
		print "Erronous work mode."

# Old school debug
#ip = "127.0.0.1"
print oldIP
print "Working mode " + mode
print remoteHost
print remoteMail
print url+retCode.text

@@ -1150,16 +1150,17 @@
 mode.%22%0A%0A
+%0A
 # Old sc
@@ -1188,16 +1188,17 @@
 .0.0.1%22%0A
+#
 print ol
@@ -1201,16 +1201,17 @@
 t oldIP%0A
+#
 print %22W
@@ -1231,16 +1231,17 @@
  + mode%0A
+#
 print re
@@ -1249,16 +1249,17 @@
 oteHost%0A
+#
 print re
@@ -1267,16 +1267,17 @@
 oteMail%0A
+#
 print ur
@@ -1291,8 +1291,9 @@
 de.text%0A
+%0A

debug codes commented out