I have a web service hosted on a home PC which is on a public dynamic ip. I also have a domain name hosted by google domains (I will refer in this post as www.example.com).
Via Google App Engine I'm able to store the dynamic IP on memcache and once a client points to myhome subdomain it will be redirected to the host ip (e.g. myhome.example.com -> 111.111.1.100).
Here is my python code running on App Engine:
import json
from webapp2 import RequestHandler, WSGIApplication
from google.appengine.api import memcache
class MainPage(RequestHandler):
# Memcache keys
key_my_current_ip = "my_current_ip"
def get(self):
response_text = "example.com is online!"
# MyHome request
if (self.request.host.lower().startswith('myhome.example.com') or
self.request.host.lower().startswith('myhome-xyz.appspot.com')):
my_current_ip = memcache.get(self.key_my_current_ip)
if my_current_ip:
url = self.request.url.replace(self.request.host, my_current_ip)
# move to https
if url.startswith("http://"):
url = url.replace("http://", "https://")
return self.redirect(url, True)
response_text = "myhome is offline!"
# Default site
self.response.headers['Content-Type'] = 'text/plain'
self.response.write(response_text)
def post(self):
try:
# Store request remote ip
body = json.loads(self.request.body)
command = body['command']
if command == 'ping':
memcache.set(key=self.key_my_current_ip, value=self.request.remote_addr)
except:
raise Exception("bad request!")
app = WSGIApplication([('/.*', MainPage),], debug=True)
What I found is that, by adding an "A" domain record, myhome.example.com will point directly to that ip without need to redirect it.
Is there a way I can update that "A" domain record using Google App Engine or Domain APIs?
def post(self):
try:
# Store request remote ip
body = json.loads(self.request.body)
command = body['command']
if command == 'ping':
**--> UPDATE "A" Record with this IP: <self.request.remote_addr>**
except:
raise Exception("bad request!")
