Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Net::HTTPSession#ipaddr

ipaddr

Returns the IP address for the connection.

If the session has not been started, returns the value set by ipaddr=, or nil if it has not been set:

Example
http = Net::HTTP.new(hostname)
http.ipaddr # => nil
http.ipaddr = '172.67.155.76'
http.ipaddr # => "172.67.155.76"

If the session has been started, returns the IP address from the socket:

Example
http = Net::HTTP.new(hostname)
http.start
http.ipaddr # => "172.67.155.76"
http.finish
See also #ipaddr= #inspect #head #keep_alive? also in 4.1 · 4.0