Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created March 10, 2014 07:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugyo/9460736 to your computer and use it in GitHub Desktop.
Save jugyo/9460736 to your computer and use it in GitHub Desktop.
Script to get TLDs from iana.org
require 'open-uri'
require 'nokogiri'
doc = Nokogiri::HTML(open('http://www.iana.org/domains/root/db'))
tlds = []
doc.css('table#tld-table tr').each do |tr|
info = tr.css('td')
next if info.empty?
tlds << {
domain: info[0].text.gsub('.', ''),
type: info[1].text
}
end
def print_tld(tlds, type)
puts tlds.select {|i| i[:type] =~ type}.map {|i| i[:domain]}.sort.join("|")
end
puts "# country-code"
print_tld(tlds, /country\-code/)
puts "# generic"
print_tld(tlds, /generic|sponsored|infrastructure|generic-restricted/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment