For my new and exciting project (hopefully more on this later) I needed to get all sub domains possibilities of a URL, so if this is the input URL:
http://a.b.c.d/test.htmlI needed to get the following sub domains:
['a.b.c.d', 'b.c.d', 'c.d', 'd']Here's the good news: this is pretty simple with Python ! :)
import urlparseNice, isn't it?
url='http://a.b.c.d/test.html'
hostname=urlparse.urlparse(url).hostname
sh=hostname.split('.')
subdomains=[".".join(sh[i:]) for i in range(len(sh))]
print subdomains
>> ['a.b.c.d', 'b.c.d', 'c.d', 'd']