Last active
December 3, 2023 11:53
-
-
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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