Skip to content

Instantly share code, notes, and snippets.

@pry0cc
Created July 30, 2016 21:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pry0cc/6646eb3b345c4cf7490f3d152e4b1ac5 to your computer and use it in GitHub Desktop.
Save pry0cc/6646eb3b345c4cf7490f3d152e4b1ac5 to your computer and use it in GitHub Desktop.
A snappy application to find out everything known about an IP.
#!/usr/bin/env ruby
require 'json'
require 'mechanize'
require 'rubygems'
require 'open-uri'
puts "Looking up #{ARGV[0]}"
agent = Mechanize.new
data = agent.get("http://freegeoip.net/json/#{ARGV[0]}").body
json = JSON.parse(data)
agent.user_agent = "curl/7.50.0"
weather = agent.get("http://wttr.in/#{json["city"]}").body.split("\n")
puts "Country Code: " + json["country_code"]
puts "Country: " + json["country_name"]
puts "Region Code: " + json["region_code"]
puts "Region Name: " + json["region_name"]
puts "City: " + json["city"]
puts "Zip Code: " + json["zip_code"]
puts "Time Zone: " + json["time_zone"]
puts "Metro Code: " + json["metro_code"].to_s
puts "Google Maps: https://www.google.com/maps?z=12&t=m&q=loc:#{json["latitude"]}+#{json["longitude"]}"
puts "Weather right now: "
puts weather[1..6]
puts ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment