Sha256: 636d4d68ebb8379f59df08cf4a01fbfd028ff6b3c6a88ab33708ddccf3793305

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 KB

Contents

#--
# Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
# Copyright (c) 2009-2011 Simone Carletti <weppos@weppos.net>
#++


module Whois
  class Server
    module Adapters

      class Arpa < Base

        def request(string)
          Server.guess(inaddr_to_ip(string)).query(string)
        end


        private

          # "127.1.168.192.in-addr.arpa" => "192.168.1.127"
          # "1.168.192.in-addr.arpa" => "192.168.1.0"
          # "168.192.in-addr.arpa" => "192.168.0.0"
          # "192.in-addr.arpa" => "192.0.0.0"
          # "in-addr.arpa" => "0.0.0.0"
          def inaddr_to_ip(string)
            unless /^([0-9]{1,3}\.?){0,4}in-addr\.arpa$/ =~ string
              raise ServerError, "Invalid .in-addr.arpa address"
            end
             a, b, c, d = string.scan(/[0-9]{1,3}\./).reverse
            [a, b, c, d].map do |token|
              token = (token ||= 0).to_i
              if token <= 255 && token >= 0
                token
              else
                raise ServerError, "Invalid .in-addr.arpa token `#{token}'"
              end
            end.join(".")
          end

      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
whois-2.2.0 lib/whois/server/adapters/arpa.rb
whois-2.1.0 lib/whois/server/adapters/arpa.rb
whois-2.0.7 lib/whois/server/adapters/arpa.rb
whois-2.0.6 lib/whois/server/adapters/arpa.rb
whois-2.0.5 lib/whois/server/adapters/arpa.rb
whois-2.0.4 lib/whois/server/adapters/arpa.rb
whois-2.0.3 lib/whois/server/adapters/arpa.rb
whois-2.0.2 lib/whois/server/adapters/arpa.rb
whois-2.0.1 lib/whois/server/adapters/arpa.rb
whois-2.0.0 lib/whois/server/adapters/arpa.rb