# File lib/geoip.rb, line 223 def city(hostname) ip = lookup_ip(hostname) # Convert numeric IP address to an integer ipnum = iptonum(ip) if (@database_type != GEOIP_CITY_EDITION_REV0 && @database_type != GEOIP_CITY_EDITION_REV1) throw "Invalid GeoIP database type, can't look up City by IP" end pos = seek_record(ipnum) # This next statement was added to MaxMind's C version after it was # rewritten in Ruby. It prevents unassigned IP addresses from returning # bogus data. There was concern over whether the changes to an # application's behaviour were always correct, but this has been tested # using an exhaustive search of the top 16 bits of the IP address space. # The records where the change takes effect contained *no* valid data. # If you're concerned, email me, and I'll send you the test program so # you can test whatever IP range you think is causing problems, # as I don't care to undertake an exhaustive search of the 32-bit space. unless pos == @database_segments[0] read_city(pos, hostname, ip) end end