Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [src/oneliner] Getting the IP from an external rescource in ruby

Reply
Thread Tools

[src/oneliner] Getting the IP from an external rescource in ruby

 
 
mrpink
Guest
Posts: n/a
 
      04-19-2007
Hi,
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(/<.+$/,'') }

greets
 
Reply With Quote
 
 
 
 
James Edward Gray II
Guest
Posts: n/a
 
      04-19-2007
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

 
Reply With Quote
 
 
 
 
Phillip Gawlowski
Guest
Posts: n/a
 
      04-19-2007
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.

 
Reply With Quote
 
mrpink
Guest
Posts: n/a
 
      04-19-2007
lol my output prints a plain IP-adress on the screen and nothing else
and you're code is of course not working because you conducted my
regular expression with an output string muahhh
 
Reply With Quote
 
James Edward Gray II
Guest
Posts: n/a
 
      04-19-2007
On Apr 19, 2007, at 8:48 AM, Phillip Gawlowski wrote:

> 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.


Wow, I am dumb today. Thanks for helping me to actually read the
email I responded to.

James Edward Gray II

 
Reply With Quote
 
Phillip Gawlowski
Guest
Posts: n/a
 
      04-19-2007
James Edward Gray II wrote:

>
> Wow, I am dumb today. Thanks for helping me to actually read the email
> I responded to.


No problem. I had similar trouble understand the email

--
Phillip "CynicalRyan" Gawlowski
http://cynicalryan.110mb.com/
http://clothred.rubyforge.org

Rule of Open-Source Programming #7:

Release early, release often. Clean compilation is optional.

 
Reply With Quote
 
John Joyce
Guest
Posts: n/a
 
      04-20-2007

On Apr 19, 2007, at 11:13 PM, Phillip Gawlowski wrote:

> James Edward Gray II wrote:
>
>> Wow, I am dumb today. Thanks for helping me to actually read the
>> email I responded to.

>
> No problem. I had similar trouble understand the email
>


One of these is a joke!

 
Reply With Quote
 
mrpink
Guest
Posts: n/a
 
      04-20-2007
what you mean?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Intstalled Ruby 1.8.7 but still getting ruby -v => 1.8.6 Mitchell Gould Ruby 6 08-18-2010 03:10 PM
Getting PHP/Smarty template functionality from Ruby or Ruby on Rails Irving Fried Ruby 2 10-15-2006 11:32 AM
#!/usr/bin/ruby , #!/usr/bin/ruby -w , #!/usr/bin/ruby -T?, #!/usr/bin/ruby -T1... anne001 Ruby 1 04-23-2006 03:02 PM
Create references to external scipt files from within an external script file Mellow Crow Javascript 6 11-04-2005 01:16 PM
unresolved external symbol/using an external dll Scott Allen C++ 8 05-02-2004 06:11 PM



Advertisments