Skip to content

Instantly share code, notes, and snippets.

@rweald
Last active December 10, 2015 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rweald/4495935 to your computer and use it in GitHub Desktop.
Save rweald/4495935 to your computer and use it in GitHub Desktop.
Read IP addresses from STDIN geocode IPs and print 2-tuple (long, lat) to STDOUT
#!/usr/bin/env ruby -W0
require 'geoip'
geocity_file_location = ARGV[0] || "./GeoLiteCity.dat"
geocoder = GeoIP.new(geocity_file_location)
i = 0
STDIN.each do |ip|
STDERR.write("Processing Line: #{i}\n") if i % 1000 == 0
i += 1
result = geocoder.city(ip.strip)
next unless result
puts "#{result.longitude},#{result.latitude}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment