Skip to content

Instantly share code, notes, and snippets.

@sjuxax
Last active March 27, 2017 21:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sjuxax/4549805 to your computer and use it in GitHub Desktop.
Save sjuxax/4549805 to your computer and use it in GitHub Desktop.
Print the local IP address of the primary interface in Ruby 1.9.3.
require 'socket'
#Socket.ip_address_list[1] is usually the IPv4 IP of eth0 (usually the primary interface).
#Socket.ip_address_list[0] is usually the IP of lo, usually 127.0.0.1
puts Socket.ip_address_list[1].ip_address
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment