How to Check If a List of ENS (.eth) Domains are Available? (Python)

5/5 - (1 vote)

You can check programmatically in Python whether a certain ENS '.eth‘ domain name is available by using the urlopen() function from urllib.request module to access the URL 'https://etherscan.io/enslookup-search?search=example.eth', replacing the URL suffix 'example.eth' with your desired domain.

In the following example code snippet, I show how you could check a list of names, one domain name per line, against the Etherscan URL and scrape the resulting HTML response to find out whether each domain is available, or not.

💡 DYI: You can copy&paste your list of candidate .eth names as shown in the example and run it on your computer or in a Jupyter Notebook. The code will provide you a list of ENS domain names that are still available.

from urllib.request import Request, urlopen
import time

# Copy your list of names here:
list_of_names = '''
Google
Apple
Amazon
Microsoft
Tencent
Facebook
Visa
McDonald's
Alibaba
AT&T
IBM
Verizon
Marlboro
Coca-Cola
Mastercard
UPS
SAP
Wells Fargo
Disney
The Home Depot
China Mobile
ICBC
Starbucks
Xfinity
Deutsche Telekom
Louis Vuitton
Spectrum
GE
Nike
PayPal
Walmart
Accenture
Samsung
Moutai
American Express
Toyota
Vodafone
Intel
Hermes
Budweiser
Baidu
Zara
Ping An
L'Oreal Paris
Oracle
Mercedes-Benz
BMW
Huawei
China Construction Bank
HSBC
YouTube
RBC
Movistar
Gucci
NTT
FedEx
Cisco
Citi
JD.com
HDFC Bank
Netflix
DHL
Shell
Pampers
Orange
TD
Chase
Commonwealth Bank of Australia
Agricultural Bank of China
Subway
Colgate
Costco
J.P. Morgan
ExxonMobil
Adobe
IKEA
Bank of America
Salesforce
China Life
US Bank
Uber
Siemens
LinkedIn
Bank of China
Gillette
AIA
KFC
Ebay
HP
SF Express
Instagram
ANZ
ALDI
BT
Lowe's
Ford
Honda
Pepsi
BCA
Adidas
'''

# Automatically extract domain names from list
names = [x.strip().lower().replace("'", '').replace(' ', '').replace('.','') + '.eth' for x in list_of_names.split()]
print(names)

# For checking the .eth domain name
url = 'https://etherscan.io/enslookup-search?search='
negative_text = b'The domain name entered is either not registered on ENS or not currently supported by Etherscan.'

# Keep track of all free domain names
free_domains = []

for name in names:
  ens_url = url + name
  req = Request(
    url=ens_url, 
    headers={'User-Agent': 'Mozilla/5.0'}
  )
  webpage = urlopen(req).read()
  if negative_text in webpage:
    free_domains.append(name)
    print(name, ' available')
  else:
    print('xxx ', name, ' xxx')
  time.sleep(1)

print('Free Domains: ', '\n'.join(free_domains))

The variable free_domains contains all ENS .eth domain names from your list that are still available.

💡 Recommended Tutorial: How to Get a Website From a Given URL in Python?