Class: Net::Whois::ARIN

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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(options = {})
  options = DEFAULT_CONNECTION.merge(options)
  self.host    = options[:host]
  self.port    = options[:port]
  self.timeout = options[:timeout]
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/net/whois/arin.rb', line 8

def host
  @host
end

#portObject

Returns the value of attribute port.



9
10
11
# File 'lib/net/whois/arin.rb', line 9

def port
  @port
end

#timeoutObject

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

Yields:

  • (self.new(options))


20
21
22
# File 'lib/net/whois/arin.rb', line 20

def self.open(options = {})
  yield self.new(options)
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