Skip to content

Instantly share code, notes, and snippets.

Last active December 3, 2023 11:53
Show Gist options
  • Save judotens/151341f04b37ffeb5b59 to your computer and use it in GitHub Desktop.
Save judotens/151341f04b37ffeb5b59 to your computer and use it in GitHub Desktop.
Export Namecheap domain zones without API
pip install selenium
python <namecheap_account> <namecheap_password> <domain>
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
print "pip install selenium dulu"
import time
import json
def get_advanced_dns_info(username, password, domain):
browser = webdriver.Firefox()
browser.get('' % str(domain))
elem = browser.find_element_by_class_name("loginForm").find_element_by_name('LoginUserName')
elem = browser.find_element_by_class_name("loginForm").find_element_by_name('LoginPassword')
elem.send_keys(str(password) + Keys.RETURN)
browser.get('' % str(domain))
isi = browser.find_element_by_tag_name('body').text
js = json.loads(isi)
return js
def parse_dns_info(dns_info):
records = dns_info['Result']['CustomHostRecords']['Records']
items = []
for record in records:
host = str(record['Host'])
if record['RecordType'] == 1: tipe = 'A'
if record['RecordType'] == 2: tipe = 'CNAME'
if record['RecordType'] == 3: tipe = 'MX'
if record['RecordType'] == 5: tipe = 'TXT'
value = str(record['Data'])
ttl = str(record['Ttl'])
priority = str(record['Priority'])
active = record['IsActive']
if not active: continue
new_value = value
if tipe == 'MX': new_value = "%s %s" % (str(priority), str(value))
items.append([host,ttl,"IN", tipe, new_value])
return items
if __name__ == "__main__":
import sys
try: dns_info = get_advanced_dns_info(sys.argv[1], sys.argv[2], sys.argv[3])
except: sys.exit("Usage: %s <namecheap_username> <namecheap_password> <domain_to_check>" % str(sys.argv[0]))
zones = parse_dns_info(dns_info)
for zone in zones:
print "\t".join(zone)
Copy link

scottwb commented Feb 22, 2018

Hey thanks for this! NameCheap has since added some anti-bot stuff like an interstitial page and sometimes a CAPTCHA. I took this and added handling of the interstitial page, warning about the CAPTCHA (don't think I can solve that one), and put a simple docker+script around it to make it easy to clone and use. Works for me to get my Zone File now!


Copy link

Hi, I have used your code to make less automatic version but it doesn't have a problem with CAPTCHA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment