Check if subdomain exists with Python 3

0

I want to check if a subdomain present on a website exists. I tried to use urllib.request.urlopen() but it returns the status code as 200 even if it does not exist. This is because my provider returns a page indicating that DNS does not exist. How can I check without the provider "getting in the way?"

    
asked by anonymous 13.03.2017 / 00:02

1 answer

3

You can use the 'gethostbyname' function of the socket library to do a DNS Lookup. Example:

import socket

try:
    ip = socket.gethostbyname('blah.google.com')
except socket.gaierror:
    print('Domínio não existe')
    
13.03.2017 / 05:12