Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to extract the DNS entries from 123-reg advanced dns page

Extract DNS entries from 123-reg advanced DNS page

123-reg do not support exporting their zone files, which prompted me to create a script to extract the DNS entries automatically.

Instructions

Read through the script to confirm for yourself that it does nothing malicious. All it does is to get the info from the page and log it to your console.

  1. Login to your 123-reg control panel.
  2. Manage the domain you want to get entries from.
  3. Go to "Manage DNS (A, MX, CNAME, TXT, SRV)".
  4. Click on the "Advanced DNS" tab.
  5. Open the Developer tools in your browser (common shortcuts include F12 or Ctrl+Shift+I).
  6. Click on the "Console" tab in developer tools.
  7. Copy and paste the above script.
  8. The output to the console should be in zone file format.

Disclaimer

I am not affiliated with 123-reg. Their advanced DNS page may change at any time, which may break this script.

License

Public Domain

var table = document.getElementsByClassName('advanced_dns')[0];
var rows = table.getElementsByTagName('tr');
var i, len, row;
var hostname, type, priority, ttl, destination;
var output = '';
output += '$TTL 600\n'; // start with default TTL
// skip header and last two rows (add new entry, delete all entries)
for (i = 1, len = rows.length - 2; i < len; i++) {
row = rows[i];
hostname = row.getElementsByClassName('dns_hostname')[0].innerText;
type = row.getElementsByClassName('dns_type')[0].innerText;
priority = row.getElementsByClassName('dns_priority')[0].innerText;
ttl = row.getElementsByClassName('dns_ttl')[0].innerText;
destination = row.getElementsByClassName('dns_data')[0].title;
if (type === 'TXT/SPF') {
if (destination.match(/^(v=spf1|spf2.0)/) !== null) {
type = 'SPF';
} else {
type = 'TXT';
}
destination = '"' + destination + '"';
}
output += [hostname, ttl, 'IN', type, priority, destination].join(' ') + '\n';
}
console.log(output);
@adamstrawson

This comment has been minimized.

Copy link

commented Jan 2, 2018

You're my hero ❤️

@candell

This comment has been minimized.

Copy link

commented Jan 15, 2018

This just saved me a nasty piece of work, thanks buddy

@g3rman42

This comment has been minimized.

Copy link

commented Feb 23, 2018

Another big thank you from Texas!

@Constantin07

This comment has been minimized.

Copy link

commented Mar 15, 2018

Many Thanks !

@alechewitt

This comment has been minimized.

Copy link

commented Mar 19, 2018

Nice one 👍

@TheFlymo

This comment has been minimized.

Copy link

commented Apr 20, 2018

Saved me an afternoon, cheers!

@barryokane

This comment has been minimized.

Copy link

commented Jun 15, 2018

Outstanding work, thanks!

@TheRusstler

This comment has been minimized.

Copy link

commented Aug 9, 2018

Great work. Saved me a lot of time, thanks for sharing!

@kieronlanning

This comment has been minimized.

Copy link

commented Oct 3, 2019

Hero!

@robwithhair

This comment has been minimized.

Copy link

commented Oct 11, 2019

This is brilliant. Thank you so much for putting this together. What a timesaver. 1 small bug is that SPF records should now be set as TXT records. When I did a diff between the name servers using the below snippet that was the only thing which came up.

diff <(sort -u <(for host in $(cat ~/.ssh/scratch); do dig +nottlid +noall +answer @ns.123-reg.co.uk $host ANY; done) ) <(sort -u <(for host in $(cat ~/.ssh/scratch); do dig +nottlid +noall +answer @ns-1341.awsdns-39.org $host ANY; done) )

When read up on SPF record type they say it should not longer be used and that TXT should be preferred from now on.

Thanks once again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.