Now HTTP_X_FORWARDED_FOR and REMOTE_ADDR are used if ip address is missing.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 8 Apr 2014 18:21:56 +0000 (20:21 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 8 Apr 2014 18:33:31 +0000 (20:33 +0200)
cgi-bin/dyndns.py

index 1d3e2d2..417c27a 100755 (executable)
@@ -148,7 +148,13 @@ try:
        # check IP address
        if not offline:
                if myip is None:
-                       raise MyipMissing()
+                       # try HTTP_X_FORWARDED_FOR
+                       myip = os.environ.get('HTTP_X_FORWARDED_FOR')
+                       if not myip: # empty string if not present
+                               # try REMOTE_ADDR
+                               myip = os.environ.get('REMOTE_ADDR')
+                               if not myip: # empty string if not present
+                                       raise MyipMissing()
                try:
                        ip = ipaddr.IPAddress(myip) # throws an exception if the IP address is not valid
                except ValueError: