Skip to content

Instantly share code, notes, and snippets.

@judotens
Last active December 3, 2023 11:53
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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.py <namecheap_account> <namecheap_password> <domain>
try:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
except:
print "pip install selenium dulu"
import time
import json
def get_advanced_dns_info(username, password, domain):
browser = webdriver.Firefox()
browser.get('https://ap.www.namecheap.com/Domains/DomainControlPanel/%s/advancedns' % str(domain))
elem = browser.find_element_by_class_name("loginForm").find_element_by_name('LoginUserName')
elem.send_keys(str(username))
elem = browser.find_element_by_class_name("loginForm").find_element_by_name('LoginPassword')
elem.send_keys(str(password) + Keys.RETURN)
time.sleep(5)
browser.get('https://ap.www.namecheap.com/Domains/dns/GetAdvancedDnsInfo?domainName=%s' % str(domain))
isi = browser.find_element_by_tag_name('body').text
browser.quit()
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)
@scottwb
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!

See: https://github.com/facetdigital/get-namecheap-zone-file

@andrew-nuwber
Copy link

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

https://gist.github.com/andrew-nuwber/3bc955e94e667cb5e62cec6de57bbef9

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