Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Ruby One-liner To Find External IP Address Across NAT Router.

DZone's Guide to

Ruby One-liner To Find External IP Address Across NAT Router.

·
Free Resource
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] })
Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}