class Wmap::GeoIPTracker
Wrapper class of the 'GeoIP' library - geoip.rubyforge.org/ For detail explanation of Geographic information of an IP address (GeoIP) and its data repository, please refer to the vendor MaxMind (www.maxmind.com)
Constants
- Db_asn
- Db_city
This product includes GeoLite data created by MaxMind, available from <a href=“http://www.maxmind.comwww.maxmind.com”>http://www.maxmind.com>.
- Db_country
Attributes
Public Class Methods
Set default instance variables
# File lib/wmap/geoip_tracker.rb, line 25 def initialize (params = {}) @verbose=params.fetch(:verbose, false) @db=params.fetch(:db, Db_city) end
Public Instance Methods
Wrapper for the Ruby GeoIP ASN class - return data structure below on successful lookup Struct.new(:number, :asn)
# File lib/wmap/geoip_tracker.rb, line 61 def asn(object) puts "Perform GeoIP ASN lookup on: #{object}" if @verbose begin object=object.strip raise "Unknown object format - only valid hostname or IP is accepted: #{object}" unless is_ip?(object) or is_fqdn?(object) GeoIP.new(Db_asn).asn(object) rescue Exception => ee puts "Exception on method asn: #{object}" if @verbose return nil end end
Wrapper for the Ruby GeoIP City class - return data structure below on successful lookup Struct.new(:request, :ip, :country_code2, :country_code3, :country_name, :continent_code, :region_name, :city_name, :postal_code, :latitude, :longitude, :dma_code, :area_code, :timezone)
# File lib/wmap/geoip_tracker.rb, line 32 def city(object) puts "Perform GeoIP city lookup on: #{object}" if @verbose begin object=object.strip raise "Unknown object format - only valid hostname or IP is accepted: #{object}" unless is_ip?(object) or is_fqdn?(object) GeoIP.new(Db_city).city(object) rescue Exception => ee puts "Exception on method city: #{object}" if @verbose return nil end end
Wrapper for the Ruby GeoIP Country class - return data structure below on successful lookup Struct.new(:request, :ip, :country_code, :country_code2, :country_code3, :country_name, :continent_code)
# File lib/wmap/geoip_tracker.rb, line 47 def country(object) puts "Perform GeoIP country lookup on: #{object}" if @verbose begin object=object.strip raise "Unknown object format - only valid hostname or IP is accepted: #{object}" unless is_ip?(object) or is_fqdn?(object) GeoIP.new(Db_country).country(object) rescue Exception => ee puts "Exception on method country: #{object}" if @verbose return nil end end