Skip to content

Instantly share code, notes, and snippets.

@rjungemann
Created September 3, 2010 00:15
Show Gist options
  • Save rjungemann/563184 to your computer and use it in GitHub Desktop.
Save rjungemann/563184 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'socket'
class IP
def self.local
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
UDPSocket.open { |s| s.connect('64.233.187.99', 1); s.addr.last }
ensure
Socket.do_not_reverse_lookup = orig
end
def self.external
`curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z/<> :]//g'`
end
end
puts IP.local, IP.external if $0 == __FILE__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment