whois 0.3.0 → 0.4.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.
data/CHANGELOG CHANGED
@@ -1,5 +1,15 @@
1
1
  = Whois CHANGELOG
2
2
 
3
+ == 0.4.0
4
+
5
+ * Add new list of IPv4 by whois programm of Marco d'Itri
6
+ * Fixed a bug of generate list of Ipv4-6. Now the search of good server is
7
+ made by higher mask before smaller.
8
+ * Add support of Ipv6, by IPAddr or String
9
+ * Add several unittest of Whois class
10
+ * Add Coverage of Code (89%)
11
+ * No support of ToRedo (RFC 4773) and 6To4 (RFC 3056)
12
+
3
13
  == 0.3.0
4
14
 
5
15
  * Add possibility construct the Whois Object with a IPAddr object
@@ -8,7 +18,7 @@
8
18
  This information is optionnal. By default it's false.
9
19
  For that the host is resolv, the second arg to Whois.new must be true
10
20
 
11
- * Add request whois whith a host String.
21
+ * Add request whois with a host String.
12
22
 
13
23
  == 0.2.1
14
24
 
data/EXAMPLES CHANGED
@@ -80,3 +80,43 @@
80
80
 
81
81
  # The host of this host
82
82
  w.host #=> fg-in-f147.google.com
83
+
84
+ == Whois request for a Ipv6 2001:0660:: like a String
85
+
86
+ require 'rubygems'
87
+ require 'whois'
88
+
89
+ w = Whois::Whois.new '2001:0660::'
90
+ w.search_whois
91
+
92
+ # All return of request
93
+ w.all
94
+
95
+ # The ip return with object IPAddr
96
+ w.ip
97
+
98
+ # The server where the request has send
99
+ w.server
100
+
101
+ # The host of this host
102
+ w.host #=> nil
103
+
104
+ == Whois request for a Ipv6 2001:0660:: like an IPAddr Object
105
+
106
+ require 'rubygems'
107
+ require 'whois'
108
+
109
+ w = Whois::Whois.new(IPAddr.new('2001:0660::'))
110
+ w.search_whois
111
+
112
+ # All return of request
113
+ w.all
114
+
115
+ # The ip return with object IPAddr
116
+ w.ip
117
+
118
+ # The server where the request has send
119
+ w.server
120
+
121
+ # The host of this host
122
+ w.host #=> nil
data/NOTES CHANGED
@@ -1,5 +1,18 @@
1
1
  = Whois Release Notes
2
2
 
3
+ == 0.4.0
4
+
5
+ Now you can create a Whois Object with an object IPAddr (require 'ipaddr')
6
+ for a Ipv6. You can create too with a String represent an IPV6.
7
+
8
+ All system of Ipv6 is not supported now with 6to4 (RFC 3056) and TeRedo (RFC 4773)
9
+
10
+ For the Ipv6 a bug must be made with creation of IPAddr like an Ipv6. If you have
11
+ compile ruby with enable the Ipv6 Support like with several OS. If This Ipv6 hasn't
12
+ a host, the IPAddr is not construct. I ask the
13
+ question[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/11049]
14
+ to Core Ruby.
15
+
3
16
  == 0.3.0
4
17
 
5
18
  Now you can create a Whois class with an object IPAddr (require 'ipaddr')
data/README CHANGED
@@ -14,14 +14,26 @@ This library is start with work to Michael Neumann. Thank to him.
14
14
 
15
15
  If you are just starting, check out the EXAMPLES[link://files/EXAMPLES.html] file.
16
16
 
17
+ == Test
18
+
19
+ This Class is test by Unit test with 8 tests and 53 assertions. You can see
20
+ the Coverage[link://coverage/index.html] of this class.
21
+
17
22
  == Authors
18
23
 
19
24
  Copyright (c) 2007 by Cyril Mougel (cyril.mougel@gmail.com)
20
25
 
21
- If you want more information on me see my blog (http://shingara.free.fr/blog),
22
- it's in french, because my english is not really good :)
26
+ If you want more information on me see my blog[http://shingara.free.fr/blog],
27
+ it's in french, because my english is not really good. An
28
+ {english version}[HTTP://shingara.free.fr/blog_en].
29
+ exist
23
30
 
24
31
  == License
25
32
 
26
33
  This library is distributed under the GPL. Please see the LICENSE file.
27
34
 
35
+ == Thanks
36
+
37
+ This project is host by RubyForge[http://rubyforge.org], the {project
38
+ page}[http://rubyforge.org/projects/whois] is on.
39
+
data/lib/data/ipv4.yaml CHANGED
@@ -39,6 +39,7 @@
39
39
  218.224.0.0/13: Nicad
40
40
  210.248.0.0/13: Nicad
41
41
  210.204.0.0/14: Nicor
42
+ 116.0.0.0/6: Apnic
42
43
  202.24.0.0/15: Nicad
43
44
  200.0.0.0/7: Lacnic
44
45
  200.17.0.0/16: Nicbr
@@ -121,7 +122,7 @@
121
122
  124.0.0.0/7: Apnic
122
123
  58.0.0.0/7: Apnic
123
124
  218.0.0.0/7: Apnic
124
- 204.0.0.0/14: Verio
125
+ 204.0.0.0/14: Ginntt
125
126
  193.0.0.0/8: Ripe
126
127
  200.20.0.0/16: Nicbr
127
128
  192.162.0.0/16: Ripe
@@ -134,15 +135,14 @@
134
135
  210.241.0.0/15: Twnic
135
136
  210.216.0.0/13: Nicor
136
137
  61.72.0.0/13: Nicor
137
- 122.0.0.0/7: Apnic
138
138
  192.114.0.0/15: Ripe
139
139
  80.0.0.0/5: Ripe
140
140
  210.188.0.0/14: Nicad
141
141
  210.178.0.0/15: Nicor
142
142
  210.90.0.0/15: Nicor
143
143
  203.180.0.0/14: Nicad
144
- 146.48.0.0/16: Ripe
145
144
  202.208.0.0/12: Nicad
145
+ 146.48.0.0/16: Ripe
146
146
  163.160.0.0/12: Ripe
147
147
  192.72.254.0/24: Arin
148
148
  213.154.32.0/19: Afrinic
@@ -165,13 +165,13 @@
165
165
  210.160.0.0/12: Nicad
166
166
  210.65.0.0/16: Twnic
167
167
  160.216.0.0/14: Ripe
168
+ 92.0.0.0/7: Ripe
168
169
  164.148.0.0/14: Afrinic
169
170
  189.0.0.0/8: Lacnic
170
171
  202.23.0.0/16: Nicad
171
172
  145.0.0.0/8: Ripe
172
173
  204.0.0.0/6: Arin
173
174
  165.143.0.0/16: Afrinic
174
- 121.0.0.0/8: Apnic
175
175
  169.208.0.0/12: Apnic
176
176
  211.104.0.0/13: Nicor
177
177
  210.196.0.0/14: Nicad
@@ -194,6 +194,7 @@
194
194
  210.62.252.0/22: Twnic
195
195
  203.224.0.0/11: Nicor
196
196
  77.0.0.0/8: Ripe
197
+ 120.0.0.0/6: Apnic
197
198
  88.0.0.0/6: Ripe
198
199
  188.0.0.0/8: Ripe
199
200
  202.13.0.0/16: Nicad
@@ -0,0 +1,33 @@
1
+ ---
2
+ 2001:4A00::/23: Ripe
3
+ 2001:4600::/23: Ripe
4
+ 2001:4200::/23: Afrinic
5
+ 2001:0200::/23: Apnic
6
+ 2400:0000::/12: Apnic
7
+ 2001:1C00::/22: Ripe
8
+ 2001:8000::/18: Apnic
9
+ 2001:1800::/23: Arin
10
+ 2001:0600::/23: Ripe
11
+ 3FFE:0000::/16: Ipv6Bone
12
+ 2001:5000::/20: Ripe
13
+ 2001:1A00::/23: Ripe
14
+ 2001:0C00::/22: Apnic
15
+ 2001:0800::/22: Ripe
16
+ 2800:0000::/12: Lacnic
17
+ 2620:0000::/23: Arin
18
+ 2001:0400::/23: Arin
19
+ 2C00:0000::/12: Afrinic
20
+ 2610:0000::/23: Arin
21
+ 2003:0000::/18: Ripe
22
+ 2001:4000::/23: Ripe
23
+ 2600:0000::/12: Arin
24
+ 2002:0000::/16: Ipv6ToIpv4
25
+ 2001:2000::/19: Ripe
26
+ 2001:0000::/32: Teredo
27
+ 2A00:0000::/12: Ripe
28
+ 2001:4C00::/22: Ripe
29
+ 2400:0000::/20: Kornet
30
+ 2001:4800::/23: Arin
31
+ 2001:4400::/23: Apnic
32
+ 2001:1400::/22: Ripe
33
+ 2001:1000::/22: Lacnic
data/lib/server/server.rb CHANGED
@@ -3,7 +3,7 @@ module Server
3
3
  # Define if the module has or not the Class in this module
4
4
  def self.class_exist? str
5
5
  begin
6
- self.class_eval str
6
+ self.class_eval str.to_s
7
7
  return true
8
8
  rescue NameError
9
9
  return false
@@ -13,7 +13,6 @@ module Server
13
13
  # Class For define a model of Server
14
14
  class Server
15
15
  attr_reader :server
16
-
17
16
  end
18
17
 
19
18
  # Class for the server Afrinic
@@ -73,5 +72,60 @@ module Server
73
72
  @server = 'whois.nic.br'
74
73
  end
75
74
  end
75
+
76
+ # Class for the teredo RFC 4773
77
+ class Teredo < Server
78
+ def initialize
79
+ @server = nil
80
+ end
81
+ end
82
+
83
+ # Class for 6To4 RFC 3056
84
+ class Ipv6ToIpv4 < Server
85
+ def initialize
86
+ @server = nil
87
+ end
88
+ end
89
+
90
+ # Class for server whois.kornet.net
91
+ class Kornet < Server
92
+ def initialize
93
+ @server = 'whois.kornet.net'
94
+ end
95
+ end
96
+
97
+ # Class for server whois.v6nic.net
98
+ class V6nic < Server
99
+ def initialize
100
+ @server = 'whois.v6nic.net'
101
+ end
102
+ end
103
+
104
+ # Class for server whois.twnic.net
105
+ class Twnic < Server
106
+ def initialize
107
+ @server = 'whois.twnic.net'
108
+ end
109
+ end
110
+
111
+ # Class for server whois.verio.net
112
+ class Verio < Server
113
+ def initialize
114
+ @server = 'whois.verio.net'
115
+ end
116
+ end
117
+
118
+ # Class for server whois.6bone.net
119
+ class Ipv6Bone < Server
120
+ def initialize
121
+ @server = 'whois.6bone.net'
122
+ end
123
+ end
124
+
125
+ class Ginntt < Server
126
+ def initialize
127
+ @server = 'rwhois.gin.ntt.net'
128
+ end
129
+ end
76
130
 
77
131
  end
data/lib/whois.rb CHANGED
@@ -4,72 +4,77 @@ require 'socket'
4
4
  require 'resolv'
5
5
  require 'ipaddr'
6
6
  require 'yaml'
7
- require 'server/server'
7
+ require File.dirname(__FILE__) + '/server/server'
8
8
 
9
9
  # Module for manage all Whois Class
10
10
  module Whois
11
11
 
12
- # Base exception of Whois
12
+ # Base exception of Whois
13
13
  class WhoisException < Exception
14
14
  end
15
15
 
16
- # Exception of Whois who made report a bug
17
- class WhoisExceptionError < WhoisException
18
- def initialize (i)
19
- WhoisException.initialize('Report a bug with error #{i} to http://rubyforge.org/projects/whois/')
20
- end
21
- end
16
+ # Exception of Whois who made report a bug
17
+ class WhoisExceptionError < WhoisException
18
+ def initialize (i)
19
+ WhoisException.initialize('Report a bug with error #{i} to http://rubyforge.org/projects/whois/')
20
+ end
21
+ end
22
22
 
23
23
  # Class to get all information about Host or IP with the Whois request
24
24
  class Whois
25
25
 
26
- Version = '0.3.0'
26
+ Version = '0.4.0'
27
27
 
28
28
  attr_reader :all
29
29
  attr_reader :server
30
30
  attr_reader :ip
31
- attr_reader :host
32
- attr_accessor :host_search
31
+ attr_reader :host
32
+ attr_accessor :host_search
33
33
 
34
34
  # Initialize with a request. The request must be an IPv4, or a host string
35
- #
36
- # The first params now is :
37
- # * a string which a Ipv4 or a host. Ipv6 not implement now
38
- # * A IPAddr instance only Ipv4 work now, no Ipv6
39
- #
40
- # A second param, host_search is optionnal. By default he is false.
41
- # If this value is true, a resolv host is made for know the host to this IPv4
42
- def initialize(request, host_search=false)
43
- @host_search = host_search
44
- if request.instance_of? IPAddr
45
- if request.ipv4?
46
- @ip = request
47
- @server = server_ipv4
48
- elsif request.ipv6?
49
- raise WhoisException.new('not implement now, only Ipv4')
50
- else
51
- raise WhoisExceptionError.new(1)
52
- end
35
+ #
36
+ # The first params now is :
37
+ # * a string which a Ipv4, Ipv6 or a host.
38
+ # * A IPAddr instance
39
+ #
40
+ # A second param, host_search is optionnal. By default he is false.
41
+ # If this value is true, a resolv host is made for know the host to this IPv4
42
+ def initialize(request, host_search=false)
43
+ @host_search = host_search
44
+ @host = nil
45
+ if request.instance_of? IPAddr
46
+ if request.ipv4?
47
+ @ip = request
48
+ @server = server_ipv4
49
+ elsif request.ipv6?
50
+ @ip = request
51
+ @server = server_ipv6
52
+ else
53
+ raise WhoisExceptionError.new(1)
54
+ end
53
55
  elsif Resolv::IPv4::Regex =~ request
54
56
  ipv4_init request
55
57
  unless self.server
56
58
  raise WhoisException.new("no server found for this IPv4 : #{request}")
57
59
  end
58
60
  elsif Resolv::IPv6::Regex =~ request
59
- raise WhoisException.new('Ipv6 not implement now')
60
- else
61
- # Test if the request is an host or not
62
- begin
63
- ip = Resolv.getaddress request
64
- @ip = IPAddr.new ip
65
- @server = server_ipv4
66
- @host = request
67
- rescue Resolv::ResolvError
68
- raise WhoisException.new('host #{request} has no DNS result')
69
- end
61
+ ipv6_init request
62
+ unless self.server
63
+ raise WhoisException.new("no server found for this Ipv6 : #{request}")
64
+ end
65
+ else
66
+ # Test if the request is an host or not
67
+ begin
68
+ ip = Resolv.getaddress request
69
+ @ip = IPAddr.new ip
70
+ @server = server_ipv4
71
+ @host = request
72
+ rescue Resolv::ResolvError
73
+ raise WhoisException.new('host #{request} has no DNS result')
74
+ end
70
75
  end
71
-
72
- search_host self.ip.to_s
76
+
77
+ search_host unless @host
73
78
  end
74
79
 
75
80
  # Ask of whois server
@@ -83,105 +88,71 @@ module Whois
83
88
  end
84
89
 
85
90
 
86
- # Search the host for this IPv4, if the value host_search is true, else host = nil
87
- def search_host
88
- begin
89
- if @host_search
90
- @host = Resolv.getname self.ip.to_s
91
- else
92
- @host = nil
93
- end
94
- rescue Resolv::ResolvError
95
- @host = nil
96
- end
97
- end
91
+ # Search the host for this IPv4, if the value host_search is true, else host = nil
92
+ def search_host
93
+ begin
94
+ if @host_search
95
+ @host = Resolv.getname self.ip.to_s
96
+ else
97
+ @host = nil
98
+ end
99
+ rescue Resolv::ResolvError
100
+ @host = nil
101
+ end
102
+ end
98
103
 
99
- private
104
+ private
100
105
 
101
106
  # Init value for a ipv4 request
102
107
  def ipv4_init (ip)
103
108
  @ip = IPAddr.new ip
104
109
  @server = server_ipv4
105
110
  end
111
+
112
+ # Init value for a ipv6 request
113
+ def ipv6_init (ip)
114
+ @ip = IPAddr.new ip
115
+ @server = server_ipv6
116
+ end
117
+
118
+ # Return the Server with the hash of mask
119
+ def server_with_hash(ip_hash)
120
+ # Sort by mask of Ip Range
121
+ arr_tmp = ip_hash.sort{|b,c| c[0][/\/(.+)/, 1].to_i <=> b[0][/\/(.+)/, 1].to_i}
122
+ arr_tmp.each do |l|
123
+ ip_range = IPAddr.new l[0]
124
+ if ip_range.include? self.ip
125
+ return Object.instance_eval("Server::#{l[1]}.new")
126
+ end
127
+ end
128
+ end
129
+
130
+ # Define the server of Whois in IPC6 list of YAML
131
+ def server_ipv6
132
+ ipv6_list = YAML::load_file(File.dirname(__FILE__) + '/data/ipv6.yaml')
133
+ server = server_with_hash(ipv6_list)
134
+ unless server.kind_of? Server::Server
135
+ raise WhoisException.new("no server found for this IPv6 : #{self.ip}")
136
+ else
137
+ return server
138
+ end
139
+ end
106
140
 
107
141
  # Define the server of Whois in IPV4 list of YAML
108
142
  def server_ipv4
109
-
110
- ipv4_list = YAML::load_file(File.dirname(__FILE__) + '/data/ipv4.yaml')
111
- # Search good Server class for this IP
112
- ipv4_list.each do |ip, server|
113
- ip_range = IPAddr.new ip
114
- if ip_range.include? self.ip
115
- return Object.instance_eval("Server::#{server}.new")
116
- end
117
- end
143
+ ipv4_list = YAML::load_file(File.dirname(__FILE__) + '/data/ipv4.yaml')
144
+ server = server_with_hash(ipv4_list)
145
+ unless server.kind_of? Server::Server
146
+ raise WhoisException.new("no server found for this IPv4 : #{self.ip}")
147
+ else
148
+ return server
149
+ end
118
150
  end
119
151
  end
120
152
  end
121
153
 
122
154
 
123
155
  if $0 == __FILE__
124
-
125
- #a = YAML::load_file('data/ipv4.yaml')
126
- #b = a[41]
127
- #b.init
128
-
129
- # puts b.server
130
-
131
- w = Whois::Whois.new '41.14.221.147'
132
- puts w.search_whois
133
-
134
- begin
135
- w = Whois::Whois.new '42.14.221.147'
136
- puts w.search_whois
137
- rescue Whois::WhoisException
138
- puts 'rescue'
139
- end
140
-
141
- # Test with Apnic Server
142
- w = Whois::Whois.new '218.14.221.147'
143
- puts w.search_whois
144
-
145
- w = Whois::Whois.new '61.80.221.147'
146
- puts w.search_whois
147
-
148
- # Test whois Ripe Server
149
- w = Whois::Whois.new '194.14.221.147'
150
- puts w.search_whois
151
-
152
- # Test whois Arin Server
153
- w = Whois::Whois.new '216.14.221.147'
154
- puts w.search_whois
155
-
156
- # Test whois Lacnic Server
157
- w = Whois::Whois.new '200.14.221.147'
158
- puts w.search_whois
159
-
160
- a = IPAddr.new '200.14.221.147'
161
- w = Whois::Whois.new(a)
162
- puts w.search_whois
163
-
164
- # ip = Resolv.getname '72.14.221.147'
165
- # puts ip
166
- #
167
- # ip = Resolv.getaddress 'google.com'
168
- # puts ip
169
- #
170
- # w = Whois::Whois.new '72.14.221.147'
171
- # puts w.search_whois
172
- #
173
- w = Whois::Whois.new 'fg-in-f147.google.com'
174
- puts w.search_whois
175
-
176
- w = Whois::Whois.new '72.14.221.147', true
177
- puts w.search_whois
178
- puts w.host
179
-
180
- puts '#################################'
181
-
182
- w = Whois::Whois.new '72.14.221.147'
183
- puts w.search_whois
184
- puts w.host
185
-
186
- # puts w.all
156
+ w = Whois::Whois.new '218.14.221.147'
157
+ puts w.search_whois
187
158
  end
data/test/example.rb ADDED
@@ -0,0 +1,110 @@
1
+
2
+ # FIRST EXAMPLE
3
+
4
+ require 'rubygems'
5
+ require '../lib/whois'
6
+
7
+ w = Whois::Whois.new '72.14.207.99'
8
+ w.search_whois
9
+
10
+ # All return of request
11
+ w.all
12
+
13
+ # The ip return with object IPAddr
14
+ w.ip
15
+
16
+ # The server where the request has send
17
+ w.server
18
+
19
+ # The host of this IPv4
20
+ w.host
21
+
22
+ # SECOND EXAMPLE
23
+
24
+ require 'ipaddr'
25
+
26
+ ip = IPAddr.new '72.17.207.99'
27
+ w = Whois::Whois.new ip
28
+ w.search_whois
29
+
30
+ # All return of request
31
+ w.all
32
+
33
+ # The ip return with object IPAddr
34
+ w.ip
35
+
36
+ # The server where the request has send
37
+ w.server
38
+
39
+ # The host of this IPv4
40
+ w.host
41
+
42
+ # THIRD EXAMPLE
43
+
44
+ w = Whois::Whois.new '72.14.221.147', true
45
+ w.search_whois
46
+
47
+ # All return of request
48
+ w.all
49
+
50
+ # The ip return with object IPAddr
51
+ w.ip
52
+
53
+ # The server where the request has send
54
+ w.server
55
+
56
+ # The host of this IPv4
57
+ w.host #=> fg-in-f147.google.com
58
+
59
+ # FOUR EXAMPLE
60
+
61
+
62
+ w = Whois::Whois.new 'fg-in-f147.google.com'
63
+ w.search_whois
64
+
65
+ # All return of request
66
+ w.all
67
+
68
+ # The ip return with object IPAddr
69
+ w.ip
70
+
71
+ # The server where the request has send
72
+ w.server
73
+
74
+ # The host of this host
75
+ w.host #=> fg-in-f147.google.com
76
+
77
+
78
+ # FIFTH EXAMPLE
79
+
80
+ w = Whois::Whois.new '2001:0660::'
81
+ w.search_whois
82
+
83
+ # All return of request
84
+ w.all
85
+
86
+ # The ip return with object IPAddr
87
+ w.ip
88
+
89
+ # The server where the request has send
90
+ w.server
91
+
92
+ # The host of this host
93
+ w.host #=> fg-in-f147.google.com
94
+
95
+ # SIX EXAMPLE
96
+
97
+ w = Whois::Whois.new(IPAddr.new('2001:0660::'))
98
+ w.search_whois
99
+
100
+ # All return of request
101
+ p w.all
102
+
103
+ # The ip return with object IPAddr
104
+ p w.ip
105
+
106
+ # The server where the request has send
107
+ p w.server
108
+
109
+ # The host of this host
110
+ p w.host #=> fg-in-f147.google.com
@@ -0,0 +1,171 @@
1
+ require 'test/unit'
2
+ require 'lib/whois'
3
+ require 'ipaddr'
4
+
5
+ class TestWhois < Test::Unit::TestCase
6
+
7
+ def test_ipv4_string
8
+ ip_with_server '72.14.207.99', Server::Arin
9
+ end
10
+
11
+ def test_rescue
12
+ ip_with_server '42.14.221.147', Server::Arin
13
+ ip_with_server '41.14.221.147', Server::Afrinic
14
+ #ip_with_server '218.14.221.147', Server::Apnic
15
+ #=> It's random, because Apnic has 2 nodes
16
+ ip_with_server '61.80.221.147', Server::Nicor
17
+ ip_with_server '194.14.221.147', Server::Ripe
18
+ ip_with_server '216.14.221.147', Server::Arin
19
+ #ip_with_server '200.14.221.147', Server::Lacnic
20
+ #=> it's random because a hour of request is renseign
21
+ end
22
+
23
+ def test_second_example
24
+
25
+ ip = IPAddr.new '72.17.207.99'
26
+ w = Whois::Whois.new ip
27
+ w.search_whois
28
+
29
+ # All return of request
30
+ assert_equal((request_whois_unix "72.17.207.99"), w.all)
31
+
32
+ # The ip return with object IPAddr
33
+ assert_equal(IPAddr.new('72.17.207.99'), w.ip)
34
+
35
+ # The server where the request has send
36
+ assert_instance_of(Server::Arin, w.server)
37
+
38
+ # The host of this IPv4
39
+ assert_nil w.host
40
+ end
41
+
42
+ def test_third_example
43
+ w = Whois::Whois.new '72.14.221.147', true
44
+ w.search_whois
45
+
46
+ # All return of request
47
+ assert_equal((request_whois_unix "72.14.221.147"), w.all)
48
+
49
+ # The ip return with object IPAddr
50
+ assert_equal((IPAddr.new '72.14.221.147'), w.ip)
51
+
52
+ # The server where the request has send
53
+ assert_instance_of Server::Arin, w.server
54
+
55
+ # The host of this IPv4
56
+ assert_equal(request_host_with_ip('72.14.221.147'), w.host)
57
+ end
58
+
59
+ def test_four_example
60
+
61
+ host = 'fg-in-f147.google.com'
62
+ w = Whois::Whois.new host
63
+ w.search_whois
64
+
65
+
66
+ # The ip return with object IPAddr
67
+ assert_equal(request_ip_with_host(host), w.ip)
68
+
69
+ assert_equal((request_whois_unix w.ip), w.all)
70
+
71
+ # The server where the request has send
72
+ assert_instance_of Server::Arin, w.server
73
+
74
+ # The host of this host
75
+ assert_equal 'fg-in-f147.google.com', w.host
76
+ end
77
+
78
+ def test_fifth_example
79
+ ip_with_server '2001:0660::', Server::Ripe
80
+ ip_with_server '2001:4200:a42e:2131', Server::Ripe, false, true
81
+ end
82
+
83
+ def test_Ipaddr_for_ipv6
84
+ ip = IPAddr.new '2001:0660::'
85
+ w = Whois::Whois.new ip
86
+ w.search_whois
87
+
88
+ # All return of request
89
+ assert_equal((request_whois_unix "2001:0660::"), w.all)
90
+
91
+ # The ip return with object IPAddr
92
+ assert_equal(IPAddr.new('2001:0660::'), w.ip)
93
+
94
+ # The server where the request has send
95
+ assert_instance_of(Server::Ripe, w.server)
96
+
97
+ # The host of this IPv4
98
+ assert_nil w.host
99
+
100
+ end
101
+
102
+ def test_Ipv6_not_host
103
+ ip = IPAddr.new 'a13e:1678:129b:7341'
104
+ assert_raise Whois::WhoisException do
105
+ w = Whois::Whois.new ip
106
+ end
107
+ end
108
+
109
+ private
110
+
111
+ def request_host_with_ip(ip)
112
+ line = IO.popen("host #{ip}")
113
+ line = line.gets
114
+ if line =~ /(.+)domain name pointer (.+)\./
115
+ Regexp.last_match 2
116
+ end
117
+ end
118
+
119
+ def request_ip_with_host(host)
120
+ line = IO.popen("host #{host}")
121
+ line = line.gets
122
+ if line =~ /(.+)has address (.+)/
123
+ IPAddr.new(Regexp.last_match(2))
124
+ end
125
+ end
126
+
127
+ def request_whois_unix(ip)
128
+ result = ''
129
+ IO.popen("whois #{ip}").each do |l|
130
+
131
+ # not good but use because ServerReferral use
132
+ if l =~ /^Renvoi/
133
+ result = result.chop().chop()
134
+ break
135
+ end
136
+
137
+ result += l
138
+ end
139
+ result
140
+ end
141
+
142
+ def ip_with_server(ip, server, read=false, except=false)
143
+ w = nil
144
+ unless except
145
+ assert_nothing_raised do
146
+ w = Whois::Whois.new ip
147
+ end
148
+ else
149
+ assert_raise Whois::WhoisException do
150
+ Whois::Whois.new(ip)
151
+ end
152
+ return
153
+ end
154
+ w.search_whois
155
+
156
+
157
+ if read
158
+ puts w.server
159
+ puts(request_whois_unix(ip))
160
+ puts w.all
161
+ puts w.ip
162
+ end
163
+
164
+ assert_equal((request_whois_unix ip).strip().gsub(/[\s]/, ''),
165
+ w.all.strip().gsub(/[\s]/, ''))
166
+ assert_equal(IPAddr.new(ip), w.ip)
167
+ assert_instance_of(server, w.server)
168
+ assert_nil w.host
169
+ end
170
+
171
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: whois
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2007-03-22 00:00:00 +01:00
6
+ version: 0.4.0
7
+ date: 2007-04-29 00:00:00 +02:00
8
8
  summary: Whois provides a library for request whois server
9
9
  require_paths:
10
10
  - lib
@@ -25,14 +25,18 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Cyril Mougel
30
31
  files:
32
+ - test/test_whois.rb
33
+ - test/example.rb
31
34
  - lib/server
32
- - lib/data
33
- - lib/whois.rb
34
35
  - lib/server/server.rb
36
+ - lib/data
35
37
  - lib/data/ipv4.yaml
38
+ - lib/data/ipv6.yaml
39
+ - lib/whois.rb
36
40
  - README
37
41
  - EXAMPLES
38
42
  - CHANGELOG