Created
February 12, 2009 16:35
-
-
Save dstarh/62709 to your computer and use it in GitHub Desktop.
get ip via ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/ruby | |
require 'net/http' | |
require 'uri' | |
require 'rubygems' | |
require 'json' | |
module JSONIP | |
$domain = 'jsonip.appspot.com' | |
class Get | |
def go(url) | |
Net::HTTP.start(url,80) do |http| | |
response = http.get("/") | |
response.body | |
end | |
end | |
end | |
class IpAddress < Get | |
def go | |
jsonip = super($domain) | |
#fix borked json | |
borked = jsonip.sub('ip','"ip"') | |
real = JSON.parse(borked) | |
real['ip'] | |
end | |
def getIt | |
go | |
end | |
end | |
end | |
blah = JSONIP::IpAddress.new | |
puts blah.getIt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment