#!/usr/bin/env ruby require 'optparse' require 'Ip2l' optparse = OptionParser.new do |opts| opts.banner = "Reverse geocoding from ip address via an HTTP request." opts.separator "" opts.separator " Usage:" opts.separator " ip2l " opts.separator "" opts.separator " Example:" opts.separator " ip2l 2.22.61.217" opts.separator "" end begin options = optparse.parse! if options.count == 0 puts "Missing argument: IP" puts optparse exit elsif options.count > 1 puts "Too many arguments" puts optparse exit end ip = options[0] rescue OptionParser::InvalidOption, OptionParser::MissingArgument puts $!.to_s puts optparse exit end ip2l = Ip2l::Ip2l.new puts ip2l.ip_to_location(ip)