Last active
March 27, 2017 21:53
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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