I am trying to get the IP address from the domain name, the problem is it gives a different IP address when the code is running locally and on the server.
Here is my code and the result when running on local
import socket
domain_str="use.typekit.net"
ip = socket.gethostbyname(domain_str.strip())
print(ip)
output > '104.86.189.35'
Here is the result of the same code running on the server
output > '62.115.253.9'
I would really appreciate it if anyone could let me know why this is happening.
CodePudding user response:
The server you are trying to reach is behind the Akamai CDN. Depending on where you connect from this CDN might give you a different IP address for optimal connectivity.
For example I get from one location:
$ dig use.typekit.net
...
use.typekit.net. 121 IN CNAME use-stls.adobe.com.edgesuite.net.
use-stls.adobe.com.edgesuite.net. 5853 IN CNAME a1988.dscg1.akamai.net.
a1988.dscg1.akamai.net. 133 IN A 89.27.242.17
a1988.dscg1.akamai.net. 133 IN A 89.27.242.41
while from another location
use.typekit.net. 28 IN CNAME use-stls.adobe.com.edgesuite.net.
use-stls.adobe.com.edgesuite.net. 21568 IN CNAME a1988.dscg1.akamai.net.
a1988.dscg1.akamai.net. 5 IN A 104.114.77.65
a1988.dscg1.akamai.net. 5 IN A 104.114.77.32
If you do a GeoIP lookup of these addresses you will see one of your addresses located in India while the other one in Sweden.