title: Getting the Hostname or IP in Ruby on Rails
body: <p>I'm in the process of maintaining a Ruby on Rails app and am looking for an easy way to find the hostname or IP address of the box I'm on (since it's a VM and new instances may have different hostnames or IP addresses). Is there a quick and easy way to do this in Ruby on Rails?</p>
  
  <p>Edit: The answer below is correct but the clarification Craig provided is useful (see also provided link in answer):</p>
  
  <blockquote>
    <p>The [below] code does NOT make a
    connection or send any packets (to
    64.233.187.99 which is google). Since UDP is a stateless protocol connect()
    merely makes a system call which
    figures out how to route the packets
    based on the address and what
    interface (and therefore IP address)
    it should bind to. addr() returns an
    array containing the family (AF_INET),
    local port, and local address (which
    is what we want) of the socket.</p>
  </blockquote>