Skip to content

Commit

Permalink
Added ability to parse ARPA hostnames even if the final IP whois is n…
Browse files Browse the repository at this point in the history
…ot supported yet.
  • Loading branch information
weppos committed Jul 7, 2009
1 parent e61b892 commit 3fd3a39
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/whois/server.rb
Expand Up @@ -144,9 +144,24 @@ def self.query_afilias(query)
end
end

# "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 self.inaddr_to_ip(query)
raise NotImplementedError

unless /^([0-9]{1,3}\.?){0,4}in-addr\.arpa$/ =~ query
raise ServerError, "Invalid .in-addr.arpa address"
end
a, b, c, d = query.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
Expand Down

0 comments on commit 3fd3a39

Please sign in to comment.