python fully qualified domain name

Viewed 635

I am using Python 3.7 socket to get the FQDN, fully qualified domain name. It works for some, e.g.

socket.getfqdn('indiana.edu')
'www.indiana.edu'

and doesn't work for others, e.g.

socket.getfqdn('google.com')
'lga34s18-in-f14.1e100.net'

Using lga34s18-in-f14.1e100.net in the browser gives the 404 error, url not found.

Ok, google.com is just one example. Here is another one:

socket.getfqdn('www.finastra.com')
'ec2-52-51-237-24.eu-west-1.compute.amazonaws.com'

And using url 'ec2-52-51-237-24.eu-west-1.compute.amazonaws.com' doesn't work, obviously. So they host their website on AWS, but why does socket return it as the FQDM, isn't 'finastra.com' the FQDM?

1 Answers

socket.getfqdn() calls socket.gethostbyaddr() (as stated in docs) to resolve the address. socket.gethostbyaddr() will issue a type A DNS request (if the domain is not on your hosts file) which will resolve to whatever the DNS of google.com or www.finastra.com is configured.

Using lga34s18-in-f14.1e100.net in the browser gives the 404 error, url not found.

This is because your browser sends a Host header which is filled with the hostname from the URL. A single webserver can serve content from different hosts. For example, the following request won't return a 404 Not Found:

curl ec2-52-51-237-24.eu-west-1.compute.amazonaws.com -H 'Host: www.finastra.com'

Removing -H 'Host: www.finastra.com' will cause the request to issue Host: ec2-52-51-237-24.eu-west-1.compute.amazonaws.com header and return 404 Not Found.

Related