Last active
August 13, 2024 06:58
-
-
Save judotens/151341f04b37ffeb5b59 to your computer and use it in GitHub Desktop.
Export Namecheap domain zones without API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install selenium | |
python namecheap.py <namecheap_account> <namecheap_password> <domain> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
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