Skip to content

Instantly share code, notes, and snippets.

@dstarh
Created February 12, 2009 16:35
Show Gist options
  • Save dstarh/62709 to your computer and use it in GitHub Desktop.
Save dstarh/62709 to your computer and use it in GitHub Desktop.
get ip via ruby
#!/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