Created
September 3, 2010 00:15
-
-
Save rjungemann/563184 to your computer and use it in GitHub Desktop.
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
#!/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