Skip to content

Instantly share code, notes, and snippets.

@jamescgibson
Created April 25, 2017 20:46
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 jamescgibson/d8946ec714270cd2ed0b990301c7acb4 to your computer and use it in GitHub Desktop.
Save jamescgibson/d8946ec714270cd2ed0b990301c7acb4 to your computer and use it in GitHub Desktop.
geocode_ip_csv
# Take a .csv file with IP addresses in a single column, and create a new file with the ip addresses
# and their associated ZIP codes
# Requires: Ruby, geocoder (gem install geocoder once ruby is installed
# Requies: File with ip addresses called ips.csv
require 'geocoder'
require 'csv'
ips = CSV.read("ips.csv").flatten
CSV.open("ip_output.csv", "w+") do |csv|
ips.each do |ip|
zip = Geocoder.search(ip).first.data["zip_code"]
csv << [ip, zip]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment