python - Extract domain name from a host name -


Is there a programming way of finding domain names from a given host name?

Given -> www. Yahoo.co.jp Return -> Yahoo To. JP

The approach that works but is very slow:

divided on "." And remove 1 group from the left, join and check the SOA record when a valid SOA record is returned, then assume that the domain

is a cleaner / faster way to do it without using regexps is?

There is no small definition that "domain name" is the parent of a particular "host name" is.

As long as you look at the SOA record, your current method of pasting is really the most accurate.

Technically, what you are doing there is a "zone cut", and in most cases that would correspond to the point at which the domain was delegated to its TLD.

Any method that relies on parsing only the text of the host name without context, DNS has been wasted for failure.

Alternatively, use the centrally maintained lists of delegation-centric domains, but be aware that these lists may be incomplete and / or outdated.

Also see where it has already finished ...


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -