Monday, October 12, 2009

I wrote a module to get information about a domain(.my) in array.

run: ruby whoisex.rb opensource.my
will return i section in array:
Amir Haris Ahmad
OPENSOURCE DOTCOM
PT 72, SEKSYEN 65, TAMAN JELUTONG,
WAKAF CHE YEH
15100 KOTA BHARU
Kelantan
Malaysia
amirharis@yahoo.com
(Tel) 012-9522020
(Fax) -


script: whoisex.rb
============
require "whois"

whois = %x{whois #{ARGV}}

a = WHOIS::Get.new


r = a.record(whois, "i")

r.each_index do |i|
puts r[i].strip
end


The module
========
module WHOIS
class Get
def record(whois, type)
st = whois =~ /#{type} \[/
en = whois =~ /#{type.next} \[/
cut= whois.slice(st..en).split("\n")
cut.pop
cut.pop
cut.shift
cut.each_index do |i|
cut[i].chomp!
end
return cut
end
end
end

Enjoy!!!!

No comments: