Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Ruby one-liner to find external IP address across NAT router.

Sometimes you just have to know what your external IP address is when there's a NAT between you and the rest of the world. Say you're in a DHCP environment that's constantly changing your IP, for example. This one-liner gives you your IP address as a string (in this case stored as "my_ip").

my_ip = (require 'open-uri' ; open("http://myip.dk") { |f| /([0-9]{1,3}\.){3}[0-9]{1,3}/.match(f.read)[0].to_a[0] })
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS