Python Dynamically Set DNS Record To IP (in Code Not By By Changing Hosts File)

- 1 answer

Is there a way to point a DNS record to IP by code? Example: Lets say www.mydns.example is pointing to IP, which is the firewall address. I want to run a python script from a serverless script (like Amazon's) to reach directly to my "real" server which is on IP (bypassing the firewall)

When I run it from a server I can change the hosts file. but I want to do it by code so I won't have to edit the local hosts file (which not functional with server-less function).

something like this:

url = "www.mydns.example"
response=urllib2.urlopen(url,ip = '')

Any idea?



Issue is solved by doing the following:

the URL should be with the IP address : and using urllib2.Request, I configured the headers and added the domain under 'host'.

like this:

import urllib2

req = urllib2.Request('',headers={'host':'www.mydns.example'})