Last active
December 10, 2015 21:38
-
-
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
This file contains hidden or 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/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