whois-arin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/net/whois/arin.rb +64 -0
  2. metadata +49 -0
@@ -0,0 +1,64 @@
1
+ require 'net/telnet'
2
+
3
+ module Net
4
+ module Whois
5
+
6
+ class ARIN
7
+
8
+ attr_accessor :host
9
+ attr_accessor :port
10
+ attr_accessor :timeout
11
+
12
+ VERSION = '0.1.0'
13
+
14
+ DEFAULT_CONNECTION = {
15
+ :host => 'whois.arin.net',
16
+ :port => 43,
17
+ :timeout => 30,
18
+ }
19
+
20
+ def self.open(options = {})
21
+ yield self.new(options)
22
+ end
23
+
24
+ def initialize(options = {})
25
+ options = DEFAULT_CONNECTION.merge(options)
26
+ self.host = options[:host]
27
+ self.port = options[:port]
28
+ self.timeout = options[:timeout]
29
+ end
30
+
31
+ def query(string)
32
+ t = Net::Telnet.new('Host' => self.host,
33
+ 'Port' => self.port,
34
+ 'Timeout' => self.timeout)
35
+ t.puts string
36
+ t.read.split(%r{\n}).reject {|line| line =~ %r{^#} }
37
+ ensure
38
+ t.close
39
+ end
40
+
41
+ def network(query)
42
+ networks = query("n + #{query}").inject([]) do |mem, line|
43
+
44
+ # ensure it matches "k: v" pairs
45
+ key, value = line.match(%r{(^\S+):\s+(.*)$}).to_a[1..2]
46
+ next mem if key.nil? || value.nil?
47
+
48
+ key.strip!
49
+ value.strip!
50
+
51
+ case (key == 'OrgName' || key == 'CustName')
52
+ when true then mem << { key => value }
53
+ when false then mem.last[key] = value
54
+ end
55
+
56
+ mem
57
+
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: whois-arin
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-07-10 00:00:00 -04:00
8
+ summary: Ruby interface to ARIN
9
+ require_paths:
10
+ - lib
11
+ email: stephen@touset.org
12
+ homepage:
13
+ rubyforge_project:
14
+ description: A simplistic interface to the ARIN whois database, similar to the API provided by Perl's Net::Whois::ARIN.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Stephen Karl Touset
31
+ files:
32
+ - lib/net
33
+ - lib/net/whois
34
+ - lib/net/whois/arin.rb
35
+ test_files: []
36
+
37
+ rdoc_options:
38
+ - -S
39
+ - -N
40
+ extra_rdoc_files: []
41
+
42
+ executables: []
43
+
44
+ extensions: []
45
+
46
+ requirements: []
47
+
48
+ dependencies: []
49
+