Over a million developers have joined DZone.

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] })

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}