From: Phillip Gawlowski Date: 2007-04-19T22:48:28+09:00 Subject: Re: [src/oneliner] Getting the IP from an external rescource in ruby James Edward Gray II wrote: > On Apr 19, 2007, at 8:10 AM, mrpink wrote: > >> just for fun I wanna share this oneliner which prints you the external >> IP on the screen :) >> >> require 'net/http' >> >> Net::HTTP.get_response(URI.parse('http://www.wieistmeineip.de')).body.scan(/^Ihre >> IP-Adresse ist.+/) { |ipadresse| puts >> ipadresse.sub(/^.+">/,'').sub(/<.+$/,'') } > > Interesting. I expected my code to be equivalent, but it gives a > different answer: > > $ ruby -r resolv -e 'p Resolv.getaddress("http://www.wieistmeineip.de")' > "212.19.62.76" > > James Edward Gray II If I may translate: the German parts into English: Net::HTTP.get_response(URI.parse('http://www.whatismyip.com')).body.scan(/^Your WAN IP is.+/) { |ipadresse| puts ipadresse.sub(/^.+">/,'').sub(/<.+$/,'') } The one liner resolves your external IP with the help of an external service. A hint for mrpink: German is not widely spoken beyond Germany, Austria and Swiss, so it's a good idea to translate your output. ;) -- Phillip "CynicalRyan" Gawlowski http://cynicalryan.110mb.com/ http://clothred.rubyforge.org Rule of Open-Source Programming #37: Duplicate effort is inevitable. Live with it.