Skip to content

Instantly share code, notes, and snippets.

@sjuxax
sjuxax / local_ip.rb
Last active March 27, 2017 21:53
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
BEGIN MESSAGE.
0QUaqkSwD5zBa0s bn2Cskhi16bOuws WcDJUBW0l2qnwo0 05OaABy4ywqfhWp
FdJhHKuGlPn1B9d ayVbIeX7MmxTCKq 6Xr2MZHgg4UwkxK RMPOKslRrko2FVG
mtAIqDdXlR55xDo UcaQrhTV38q91xa n8tMN8lm5jLKaPO X44aSC1OlahqhOG
jVTdlKqpj2Q7RHV 3OnGJy5qmHKpWT6 mGCva21.
END MESSAGE.