Browse files

Add arin adapter to handle ReferralServer directives (fixes #37).

  • Loading branch information...
1 parent b56b858 commit 88b3f3c53bc456ff0537a1425f766e569f6e982f @linrock committed Feb 5, 2013
Showing with 77 additions and 12 deletions.
  1. +23 −12 data/ipv4.json
  2. +1 −0 lib/whois/server.rb
  3. +53 −0 lib/whois/server/adapters/arin.rb
View
35 data/ipv4.json
@@ -145,7 +145,8 @@
"host": "whois.apnic.net"
},
"0.0.0.0/1": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"133.0.0.0/8": {
"host": "whois.nic.ad.jp"
@@ -163,7 +164,8 @@
"host": "whois.ripe.net"
},
"141.86.0.0/16": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"141.64.0.0/11": {
"host": "whois.ripe.net"
@@ -364,16 +366,19 @@
"host": "whois.lacnic.net"
},
"128.0.0.0/2": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"192.71.0.0/16": {
"host": "whois.ripe.net"
},
"192.72.253.0/24": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"192.72.254.0/24": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"192.72.0.0/16": {
"host": "whois.apnic.net"
@@ -397,7 +402,8 @@
"host": "whois.ripe.net"
},
"192.0.0.0/8": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"193.0.0.0/8": {
"host": "whois.ripe.net"
@@ -409,7 +415,8 @@
"host": "whois.afrinic.net"
},
"198.0.0.0/7": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"200.17.0.0/16": {
"host": "whois.nic.br"
@@ -505,10 +512,12 @@
"host": "rwhois.gin.ntt.net"
},
"204.0.0.0/6": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"208.0.0.0/7": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"209.94.192.0/19": {
"host": "whois.lacnic.net"
@@ -634,10 +643,12 @@
"host": "whois.ripe.net"
},
"214.0.0.0/7": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"216.0.0.0/8": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"217.0.0.0/8": {
"host": "whois.ripe.net"
@@ -720,4 +731,4 @@
"220.0.0.0/6": {
"host": "whois.apnic.net"
}
-}
+}
View
1 lib/whois/server.rb
@@ -25,6 +25,7 @@ class Server
# customized to handle WHOIS queries for a type or a group of servers.
module Adapters
autoload :Base, "whois/server/adapters/base"
+ autoload :Arin, "whois/server/adapters/arin"
autoload :Arpa, "whois/server/adapters/arpa"
autoload :Afilias, "whois/server/adapters/afilias"
autoload :Formatted, "whois/server/adapters/formatted"
View
53 lib/whois/server/adapters/arin.rb
@@ -0,0 +1,53 @@
+#--
+# Ruby Whois
+#
+# An intelligent pure Ruby WHOIS client and parser.
+#
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
+#++
+
+
+module Whois
+ class Server
+ module Adapters
+
+ #
+ # = Arin Adapter
+ #
+ # Provides ability to query Arin WHOIS interfaces.
+ #
+ class Arin < Base
+
+ # Executes a WHOIS query to the Arin WHOIS interface,
+ # resolving any intermediate referral,
+ # and appends the response to the client buffer.
+ #
+ # @param [String] string
+ # @return [void]
+ #
+ def request(string)
+ response = query_the_socket(string, host)
+ buffer_append response, host
+
+ if options[:referral] != false && referral = extract_referral(response)
+ response = query_the_socket(string, referral[:host], referral[:port])
+ buffer_append(response, referral[:host])
+ end
+
+ end
+
+ private
+
+ def extract_referral(response)
+ return unless response[/ReferralServer:\s*r?whois:\/\/([\w\.]+):?(\d+)/]
+ {
+ :host => $1,
+ :port => $2 ? $2.to_i : nil
+ }
+ end
+
+ end
+
+ end
+ end
+end

0 comments on commit 88b3f3c

Please sign in to comment.