Skip to content

Instantly share code, notes, and snippets.

@bbozo
Last active December 17, 2015 00:49
Show Gist options
  • Save bbozo/5523578 to your computer and use it in GitHub Desktop.
Save bbozo/5523578 to your computer and use it in GitHub Desktop.
finds IP addresses from MaxMinds GeoLite city CSV dump
require 'csv'
# address = '245.245.245.245'
address = '24.24.24.24'
def ip_address_to_int address
( o1, o2, o3, o4 ) = address.split('.').map(&:to_i)
16777216 * o1 + 65536 * o2 + 256 * o3 + o4
end
integer_ip = ip_address_to_int address
puts "Searching for #{address} coded to #{integer_ip}"
counter = 0
CSV.foreach('GeoLiteCity-Blocks.csv') do |row|
counter += 1
if row[0].to_i <= integer_ip and integer_ip < row[1].to_i
puts row
end
printf "." if counter%1000 == 0
end
$ grep 23794, GeoLiteCity-Location.csv
23794,"HK","00","Tsuen Wan","",22.3667,114.1000,,
$ grep 29690, GeoLiteCity-Location.csv
29690,"US","NY","East Syracuse","13057",43.0892,-76.0250,555,315
Searching for 24.24.24.24 coded to 404232216
...................................................................................................404228096
404234239
29690
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
# ALSO,
Searching for 116.48.136.76 coded to 1949337676
.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................1949337600
1949338111
23794
........................................................................................................................................................................................................................................................
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment