# Wraps an HTTP client to see which domains of my blog respond to an HTTP GET.

require 'net/http'

BLOGGER_DOMAIN_BASE = "http://brikis98.blogspot"

# From http://dishingtech.blogspot.com/2012/06/list-of-blogger-country-domains-for.html
DOMAINS = [
  "ca",
  "co.uk",
  "com",
  "com.ac",
  "com.ad",
  "com.ae",
  "com.ag",
  "com.ai",
  "com.al",
  "com.am",
  "com.an",
  "com.ao",
  "com.aq",
  "com.ar",
  "com.as",
  "com.at",
  "com.au",
  "com.aw",
  "com.ax",
  "com.az",
  "com.ba",
  "com.bb",
  "com.bd",
  "com.be",
  "com.bf",
  "com.bg",
  "com.bh",
  "com.bi",
  "com.bj",
  "com.bm",
  "com.bn",
  "com.bo",
  "com.br",
  "com.bs",
  "com.bt",
  "com.bw",
  "com.by",
  "com.bz",
  "com.ca",
  "com.cc",
  "com.cd",
  "com.cf",
  "com.cg",
  "com.ch",
  "com.ci",
  "com.ck",
  "com.cl",
  "com.cm",
  "com.cn",
  "com.co",
  "com.cr",
  "com.cu",
  "com.cv",
  "com.cx",
  "com.cy",
  "com.cz",
  "com.de",
  "com.dj",
  "com.dk",
  "com.dm",
  "com.do",
  "com.dz",
  "com.ec",
  "com.ee",
  "com.eg",
  "com.er",
  "com.es",
  "com.et",
  "com.eu",
  "com.fi",
  "com.fj",
  "com.fk",
  "com.fm",
  "com.fo",
  "com.fr",
  "com.ga",
  "com.gd",
  "com.ge",
  "com.gf",
  "com.gg",
  "com.gh",
  "com.gi",
  "com.gl",
  "com.gm",
  "com.gn",
  "com.gp",
  "com.gq",
  "com.gr",
  "com.gs",
  "com.gt",
  "com.gu",
  "com.gw",
  "com.gy",
  "com.hk",
  "com.hm",
  "com.hn",
  "com.hr",
  "com.ht",
  "com.hu",
  "com.id",
  "com.ie",
  "com.il",
  "com.im",
  "com.in",
  "com.io",
  "com.iq",
  "com.ir",
  "com.is",
  "com.it",
  "com.je",
  "com.jm",
  "com.jo",
  "com.jp",
  "com.ke",
  "com.kg",
  "com.kh",
  "com.ki",
  "com.km",
  "com.kn",
  "com.kp",
  "com.kr",
  "com.kw",
  "com.ky",
  "com.kz",
  "com.la",
  "com.lb",
  "com.lc",
  "com.li",
  "com.lk",
  "com.lr",
  "com.ls",
  "com.lt",
  "com.lu",
  "com.lv",
  "com.ly",
  "com.ma",
  "com.mc",
  "com.md",
  "com.me",
  "com.mg",
  "com.mh",
  "com.mk",
  "com.ml",
  "com.mm",
  "com.mn",
  "com.mo",
  "com.mp",
  "com.mq",
  "com.mr",
  "com.ms",
  "com.mt",
  "com.mu",
  "com.mv",
  "com.mw",
  "com.mx",
  "com.my",
  "com.mz",
  "com.na",
  "com.nc",
  "com.ne",
  "com.nf",
  "com.ng",
  "com.ni",
  "com.nl",
  "com.no",
  "com.np",
  "com.nr",
  "com.nu",
  "com.nz",
  "com.om",
  "com.pa",
  "com.pe",
  "com.pf",
  "com.pg",
  "com.ph",
  "com.pk",
  "com.pl",
  "com.pm",
  "com.pn",
  "com.pr",
  "com.ps",
  "com.pt",
  "com.pw",
  "com.py",
  "com.qa",
  "com.re",
  "com.ro",
  "com.rs",
  "com.ru",
  "com.rw",
  "com.sa",
  "com.sb",
  "com.sc",
  "com.sd",
  "com.se",
  "com.sg",
  "com.sh",
  "com.si",
  "com.sk",
  "com.sl",
  "com.sm",
  "com.sn",
  "com.so",
  "com.sr",
  "com.st",
  "com.su",
  "com.sv",
  "com.sy",
  "com.sz",
  "com.tc",
  "com.td",
  "com.tf",
  "com.tg",
  "com.th",
  "com.tj",
  "com.tk",
  "com.tl",
  "com.tm",
  "com.tn",
  "com.to",
  "com.tp",
  "com.tr",
  "com.tt",
  "com.tv",
  "com.tw",
  "com.ua",
  "com.ug",
  "com.uk",
  "com.us",
  "com.uy",
  "com.uz",
  "com.va",
  "com.vc",
  "com.ve",
  "com.vg",
  "com.vi",
  "com.vn",
  "com.vu",
  "com.ws",
  "com.ye",
  "com.yt",
  "com.za",
  "com.zm",
  "com.zw",
  "de",
  "gr",
  "in",
  "mx",
  "ch",
  "fr",
  "ie",
  "it",
  "nl",
  "pt",
  "ro",
  "sg",
  "be",
  "no",
  "se "
]

good_domains = []
DOMAINS.each do |domain|
  uri = URI.parse("#{BLOGGER_DOMAIN_BASE}.#{domain}")
  puts "Making HTTP GET to #{uri}"

  http = Net::HTTP.new(uri.host, uri.port)
  http.read_timeout = 1 # seconds

  begin
    http.request_get(uri) do |response|
      code = response.code.to_i
      puts "Got response #{code}"
      if code >= 200 && code < 300
        good_domains.push(domain)
      end
    end
  rescue Exception => e
    puts "Got an exception #{e}"
  end
end

puts "Good domains:\n#{good_domains}"


# The result as of 04/17/15
# GOOD_DOMAINS = [
#   "ca",
#   "co.uk",
#   "com",
#   "com.ar",
#   "com.au",
#   "com.ba",
#   "com.be",
#   "com.br",
#   "com.de",
#   "com.es",
#   "com.gs",
#   "com.my",
#   "com.pa",
#   "com.ph",
#   "com.pn",
#   "com.ru",
#   "com.tr",
#   "com.ua",
#   "com.vn",
#   "de",
#   "gr",
#   "in",
#   "mx",
#   "ch",
#   "fr",
#   "ie",
#   "it",
#   "nl",
#   "pt",
#   "ro",
#   "sg",
#   "be",
#   "no",
#   "se"
# ]
