Check if subdomain exists with Python 3

Asked

Viewed 470 times

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 the DNS does not exist. How can I check without the provider "disturbing"?

1 answer

3


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

import socket

try:
    ip = socket.gethostbyname('blah.google.com')
except socket.gaierror:
    print('Domínio não existe')
  • Thanks, solved my problem. ^-^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.