I made a server in python, that after an incoming HTTP request it sends requests to other servers. Sometimes it's the case that it sends a request to himself, which causes a problem. Is there a way to detect if an IP address is it's own address?
It's running in a virtual machine in a cloud, without access to the outside Internet. So is there a way to detect that for example 10.158.3.251:5555 is the localhost of the machine running the code?
Edit: Getting the IP address now from ifconfig command. It feels clumsy, but it's working:
cmd = "/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'"
self.ip = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
Open for better solutions, problem is that the expected mapping (10.158.3.250 virtual-158-3-250.xxx.xx) is not in the /etc/hosts file.