Created
December 30, 2008 17:25
-
-
Save lantins/41671 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'net/https' | |
require 'hpricot' | |
# Luke Antins - http://lividpenguin.com/ | |
# very quick scrap script to build dns zone files from 123-reg data. | |
# used for migrating from 123-reg's dns servers. | |
def scrape_for_dns_records(domain_name) | |
http = Net::HTTP.new('www.123-reg.co.uk', 443) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
resource_records = Array.new | |
http.start do |http| | |
request = Net::HTTP::Get.new("/secure/cp/ca.cgi?domain=#{domain_name}") | |
request.basic_auth 'username', 'password' | |
response = http.request(request) | |
response.value | |
doc = Hpricot(response.body) | |
(doc/"/html/body/form[4]/table/tr:gt(1)").each do |tr| | |
tds = tr.search('td') | |
# a, txt, cname record information | |
if tds.length == 4 then | |
record_name = tds.first.inner_text.downcase | |
record_type = tds.search('select/option[@selected]').first['value'].upcase | |
record_content = tds[2].search('input[@type=text]').first['value'].downcase | |
rr = { | |
'name' => record_name, | |
'ttl' => '', | |
'protocol' => 'IN', | |
'rr' => record_type, | |
'data' => record_content | |
} | |
resource_records << rr | |
end | |
tds = tr.search('td/input') | |
# mx records | |
if tds.length == 3 then | |
record_server = tds[0]['value'].downcase | |
record_priority = tds[1]['value'].downcase | |
rr = { | |
'name' => '', | |
'ttl' => '', | |
'protocol' => 'IN', | |
'rr' => 'MX', | |
'data' => { 'priority' => record_priority, 'data' => record_server } | |
} | |
resource_records << rr | |
end | |
end | |
end | |
return resource_records | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment