Last active
December 17, 2015 00:49
-
-
Save bbozo/5523578 to your computer and use it in GitHub Desktop.
finds IP addresses from MaxMinds GeoLite city CSV dump
This file contains 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
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 |
This file contains 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
$ grep 23794, GeoLiteCity-Location.csv | |
23794,"HK","00","Tsuen Wan","",22.3667,114.1000,, |
This file contains 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
$ grep 29690, GeoLiteCity-Location.csv | |
29690,"US","NY","East Syracuse","13057",43.0892,-76.0250,555,315 |
This file contains 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
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