Skip to content

Instantly share code, notes, and snippets.

@hron84
Created April 26, 2011 10:09
Show Gist options
  • Save hron84/942071 to your computer and use it in GitHub Desktop.
Save hron84/942071 to your computer and use it in GitHub Desktop.
Check domain on domain.hu
#!/usr/bin/env ruby
require 'uri'
require 'net/http'
require 'iconv'
if ARGV.size < 1 or ARGV[0] == '--help'
puts "Usage: #{File.basename(__FILE__)} DOMAIN"
exit 1
end
p = ARGV.shift.split(/\./)
tld = p.pop
if tld != 'hu'
puts "This script can query only .hu TLD"
exit 1
end
if %w(co info org priv sport tm 2000 agrar bolt casino city erotica erotika film forum games hotel ingatlan jogasz konyvelo lakas media news reklam sex shop suli szex tozsde utazas video).include?(p.last)
tld = p.pop + "." + tld
end
domain = p.join('.')
url = "http://www.domain.hu/domain/szabad-e/?domain=#{domain}&tld=#{tld}"
uri = URI.parse url
result = ""
Net::HTTP.start(uri.host) do |http|
headers = {
'Referer' => 'http://www.domain.hu/szabad-e/',
'User-Agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; hu-hu) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5',
}
rsp = http.get(uri.request_uri, headers)
result = rsp.body
end
r = result.scan(/<h3[^>]*>(.*?)<\/h3>/m)
if r.empty?
puts "ERROR: invalid string got. Here is a code:"
puts "------------------------------------------"
puts
puts result
exit 1
else
msg = r[0][0]
end
msg.gsub!(/<[^>]+>/, "")
msg.gsub!(/\s+/, " ")
msg = Iconv.iconv('UTF-8', 'ISO-8859-2', msg)
puts msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment