Created
September 9, 2010 10:11
-
-
Save hron84/571682 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 'uri' | |
require 'net/http' | |
require 'open-uri' | |
if ARGV.size < 1 or ARGV[0] == '--help' | |
puts "Usage: #{File.basename(__FILE__)} DOMAIN [NS]" | |
exit 1 | |
end | |
url = "http://www.domain.hu/domain/regcheck/?dname=#{ARGV[0].downcase}" + (ARGV.size == 2 ? "&host=#{ARGV[1]}" : "") | |
uri = URI.parse url | |
headers = { | |
'Referer' => 'http://www.domain.hu/regcheck/', | |
'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', | |
} | |
http = Net::HTTP.start(uri.host, uri.port) | |
response = http.get(uri.path + '?' + uri.query, headers) | |
result = response.body | |
r = result.scan(/<code[^>]*>(.*?)<\/code>/m) | |
if r.empty? | |
puts "ERROR: invalid string got. Here is a code:" | |
puts "------------------------------------------" | |
puts | |
puts result | |
exit 1 | |
else | |
code = r[0][0] | |
end | |
code.gsub!(/<[^>]+>/, "") | |
code.gsub!(/\n+/, "\n") | |
domain = "" | |
code.each_line do |line| | |
line.strip! | |
b=line.scan(/(\S+)\s+(-[IWES]-)\s+(\[\S+\])\s+(.*)/) | |
unless b.empty? | |
domain = b[0][2] | |
puts format('%-7s %3s %s %s', b[0][0], b[0][1], b[0][2], b[0][3]) | |
else | |
# Very dirty hack to handle multiple MX address | |
spcnum = 7 + 1 + 3 + 1 + domain.size + 1 | |
spcnum.times { print ' ' } | |
puts line | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment