Class: Net::Whois::ARIN
- Inherits:
-
Object
- Object
- Net::Whois::ARIN
- Defined in:
- lib/net/whois/arin.rb
Constant Summary collapse
- VERSION =
'0.1.0'
- DEFAULT_CONNECTION =
{ :host => 'whois.arin.net', :port => 43, :timeout => 30, }
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ARIN
constructor
A new instance of ARIN.
- #network(query) ⇒ Object
- #query(string) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ARIN
Returns a new instance of ARIN.
24 25 26 27 28 29 |
# File 'lib/net/whois/arin.rb', line 24 def initialize( = {}) = DEFAULT_CONNECTION.merge() self.host = [:host] self.port = [:port] self.timeout = [:timeout] end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/net/whois/arin.rb', line 8 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'lib/net/whois/arin.rb', line 9 def port @port end |
#timeout ⇒ Object
Returns the value of attribute timeout.
10 11 12 |
# File 'lib/net/whois/arin.rb', line 10 def timeout @timeout end |
Class Method Details
.open(options = {}) {|self.new(options)| ... } ⇒ Object
20 21 22 |
# File 'lib/net/whois/arin.rb', line 20 def self.open( = {}) yield self.new() end |
Instance Method Details
#network(query) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/net/whois/arin.rb', line 41 def network(query) networks = query("n + #{query}").inject([]) do |mem, line| # ensure it matches "k: v" pairs key, value = line.match(%r{(^\S+):\s+(.*)$}).to_a[1..2] next mem if key.nil? || value.nil? key.strip! value.strip! case (key == 'OrgName' || key == 'CustName') when true then mem << { key => value } when false then mem.last[key] = value end mem end end |
#query(string) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/net/whois/arin.rb', line 31 def query(string) t = Net::Telnet.new('Host' => self.host, 'Port' => self.port, 'Timeout' => self.timeout) t.puts string t.read.split(%r{\n}).reject {|line| line =~ %r{^#} } ensure t.close end |