Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow binding the whois TCP socket to a specific IP address #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/whois.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module Whois
# ==== Parameters # ==== Parameters
# #
# qstring:: The String to be sent as query parameter. # qstring:: The String to be sent as query parameter.
# options:: Options passed to the server adapter.
# #
# ==== Returns # ==== Returns
# #
Expand All @@ -50,8 +51,8 @@ module Whois
# Whois::Client.new.query("google.com") # Whois::Client.new.query("google.com")
# # => #<Whois::Answer> # # => #<Whois::Answer>
# #
def self.query(qstring) def self.query(qstring, options = { })
Client.new.query(qstring) Client.new.query(qstring, options)
end end


# Checks whether the object represented by <tt>qstring</tt> is available. # Checks whether the object represented by <tt>qstring</tt> is available.
Expand Down Expand Up @@ -126,8 +127,8 @@ def self.registered?(qstring)




# See <tt>Whois#query</tt>. # See <tt>Whois#query</tt>.
def self.whois(qstring) def self.whois(qstring, options = { })
query(qstring) query(qstring, options)
end end




Expand Down
4 changes: 3 additions & 1 deletion lib/whois/client.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ def initialize(options = {}, &block)
# client.query("google.com") # client.query("google.com")
# # => #<Whois::Answer> # # => #<Whois::Answer>
# #
def query(qstring) def query(qstring, options = { })
string = qstring.to_s string = qstring.to_s
Timeout::timeout(timeout) do Timeout::timeout(timeout) do
@server = Server.guess(string) @server = Server.guess(string)
# for some reason, a few tests fail without the respond_to? check
@server.options.merge!(options) if @server.respond_to?(:options)
@server.query(string) @server.query(string)
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion lib/whois/server/adapters/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def query_the_socket(qstring, host, port = nil)
private private


def ask_the_socket(qstring, host, port) def ask_the_socket(qstring, host, port)
client = TCPSocket.open(host, port) client = TCPSocket.open(host, port, options[:bind_address])
client.write("#{qstring}\r\n") # I could use put(foo) and forget the \n client.write("#{qstring}\r\n") # I could use put(foo) and forget the \n
client.read # but write/read is more symmetric than puts/read client.read # but write/read is more symmetric than puts/read
ensure # and I really want to use read instead of gets. ensure # and I really want to use read instead of gets.
Expand Down