whois 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/CHANGELOG +10 -0
  2. data/EXAMPLES +75 -11
  3. data/NOTES +9 -0
  4. data/README +3 -0
  5. data/lib/whois.rb +81 -9
  6. metadata +2 -2
data/CHANGELOG CHANGED
@@ -1,5 +1,15 @@
1
1
  = Whois CHANGELOG
2
2
 
3
+ == 0.3.0
4
+
5
+ * Add possibility construct the Whois Object with a IPAddr object
6
+
7
+ * Add the host information when you search a whois with an Ipv4.
8
+ This information is optionnal. By default it's false.
9
+ For that the host is resolv, the second arg to Whois.new must be true
10
+
11
+ * Add request whois whith a host String.
12
+
3
13
  == 0.2.1
4
14
 
5
15
  * Fix bug in gem where the data/ipv4.yaml is not load
data/EXAMPLES CHANGED
@@ -1,18 +1,82 @@
1
1
  = Whois examples
2
2
 
3
- == Whois request for IP 72.14.207.99
3
+ == Whois request for IP 72.14.207.99, with IP like a string
4
4
 
5
- require 'rubygems'
6
- require 'whois'
5
+ require 'rubygems'
6
+ require 'whois'
7
7
 
8
- w = Whois::Whois.new '72.14.207.99'
9
- w.search_whois
8
+ w = Whois::Whois.new '72.14.207.99'
9
+ w.search_whois
10
10
 
11
- # All return of request
12
- w.all
11
+ # All return of request
12
+ w.all
13
13
 
14
- # The ip return with object IPAddr
15
- w.ip
14
+ # The ip return with object IPAddr
15
+ w.ip
16
16
 
17
- # The server where the request has send
18
- w.server
17
+ # The server where the request has send
18
+ w.server
19
+
20
+ # The host of this IPv4
21
+ w.host
22
+
23
+ == Whois request for IP 72.14.207.99, with IP like a IPAddr instance
24
+
25
+ require 'rubygems'
26
+ require 'whois'
27
+ require 'ipaddr'
28
+
29
+ ip = IPAddr.new '72.17.207.99'
30
+ w = Whois::Whois.new ip
31
+ w.search_whois
32
+
33
+ # All return of request
34
+ w.all
35
+
36
+ # The ip return with object IPAddr
37
+ w.ip
38
+
39
+ # The server where the request has send
40
+ w.server
41
+
42
+ # The host of this IPv4
43
+ w.host
44
+
45
+ == Whois request for IP 72.14.207.99 with resolv host
46
+
47
+ require 'rubygems'
48
+ require 'whois'
49
+
50
+ w = Whois::Whois.new '72.14.221.147', true
51
+ w.search_whois
52
+
53
+ # All return of request
54
+ w.all
55
+
56
+ # The ip return with object IPAddr
57
+ w.ip
58
+
59
+ # The server where the request has send
60
+ w.server
61
+
62
+ # The host of this IPv4
63
+ w.host #=> fg-in-f147.google.com
64
+
65
+ == Whois request for a Host
66
+
67
+ require 'rubygems'
68
+ require 'whois'
69
+
70
+ w = Whois::Whois.new 'fg-in-f147.google.com'
71
+
72
+ # All return of request
73
+ w.all
74
+
75
+ # The ip return with object IPAddr
76
+ w.ip
77
+
78
+ # The server where the request has send
79
+ w.server
80
+
81
+ # The host of this host
82
+ w.host #=> fg-in-f147.google.com
data/NOTES CHANGED
@@ -1,5 +1,14 @@
1
1
  = Whois Release Notes
2
2
 
3
+ == 0.3.0
4
+
5
+ Now you can create a Whois class with an object IPAddr (require 'ipaddr')
6
+
7
+ You can obtains the host name for your IP when you made a request Ipv4. This
8
+ resolv must be made if you put a true in second arguments for the initialize
9
+
10
+ You can too made a request Whois with a host, now
11
+
3
12
  == 0.2.1
4
13
 
5
14
  Release for fix bugs
data/README CHANGED
@@ -18,6 +18,9 @@ If you are just starting, check out the EXAMPLES[link://files/EXAMPLES.html] fil
18
18
 
19
19
  Copyright (c) 2007 by Cyril Mougel (cyril.mougel@gmail.com)
20
20
 
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 :)
23
+
21
24
  == License
22
25
 
23
26
  This library is distributed under the GPL. Please see the LICENSE file.
data/lib/whois.rb CHANGED
@@ -6,28 +6,70 @@ require 'ipaddr'
6
6
  require 'yaml'
7
7
  require 'server/server'
8
8
 
9
+ # Module for manage all Whois Class
9
10
  module Whois
10
11
 
12
+ # Base exception of Whois
11
13
  class WhoisException < Exception
12
14
  end
13
15
 
14
- # Class to get all information about Host or IP with the Whois
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
+
23
+ # Class to get all information about Host or IP with the Whois request
15
24
  class Whois
16
25
 
26
+ Version = '0.3.0'
27
+
17
28
  attr_reader :all
18
29
  attr_reader :server
19
30
  attr_reader :ip
20
-
21
- # Initialize with a request. The request must be an IPv4
22
- def initialize(request)
23
- if /^\d+\.\d+\.\d+\.\d+$/ =~ request
31
+ attr_reader :host
32
+ attr_accessor :host_search
33
+
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
53
+ elsif Resolv::IPv4::Regex =~ request
24
54
  ipv4_init request
25
55
  unless self.server
26
56
  raise WhoisException.new("no server found for this IPv4 : #{request}")
27
57
  end
28
- else
29
- raise WhoisException.new('not implement now, only Ipv4')
58
+ 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
30
70
  end
71
+
72
+ search_host self.ip.to_s
31
73
  end
32
74
 
33
75
  # Ask of whois server
@@ -40,7 +82,21 @@ module Whois
40
82
  @all = ret
41
83
  end
42
84
 
43
- private
85
+
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
98
+
99
+ private
44
100
 
45
101
  # Init value for a ipv4 request
46
102
  def ipv4_init (ip)
@@ -50,7 +106,8 @@ module Whois
50
106
 
51
107
  # Define the server of Whois in IPV4 list of YAML
52
108
  def server_ipv4
53
- ipv4_list = YAML::load_file(File.dirname(__FILE__) + '/data/ipv4.yaml')
109
+
110
+ ipv4_list = YAML::load_file(File.dirname(__FILE__) + '/data/ipv4.yaml')
54
111
  # Search good Server class for this IP
55
112
  ipv4_list.each do |ip, server|
56
113
  ip_range = IPAddr.new ip
@@ -100,6 +157,10 @@ if $0 == __FILE__
100
157
  w = Whois::Whois.new '200.14.221.147'
101
158
  puts w.search_whois
102
159
 
160
+ a = IPAddr.new '200.14.221.147'
161
+ w = Whois::Whois.new(a)
162
+ puts w.search_whois
163
+
103
164
  # ip = Resolv.getname '72.14.221.147'
104
165
  # puts ip
105
166
  #
@@ -111,5 +172,16 @@ if $0 == __FILE__
111
172
  #
112
173
  w = Whois::Whois.new 'fg-in-f147.google.com'
113
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
+
114
186
  # puts w.all
115
187
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: whois
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.1
7
- date: 2007-03-21 00:00:00 +01:00
6
+ version: 0.3.0
7
+ date: 2007-03-22 00:00:00 +01:00
8
8
  summary: Whois provides a library for request whois server
9
9
  require_paths:
10
10
  - lib