Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Net::HTTPSession#ipaddr
ipaddr
lib/net/http.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/net/http.rb, line 1345
def ipaddr
started? ? @socket.io.peeraddr[3] : @ipaddr
end
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