Class: Wmap::GeoIPTracker

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/wmap/geoip_tracker.rb

Overview

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)

Constant Summary collapse

Db_city =

This product includes GeoLite data created by MaxMind, available from <a href=“www.maxmind.com”>www.maxmind.com</a>.

File.dirname(__FILE__)+"/../../dicts/GeoLiteCity.dat"
Db_asn =
File.dirname(__FILE__)+"/../../dicts/GeoIPASNum.dat"
Db_country =
File.dirname(__FILE__)+"/../../dicts/GeoIP.dat"

Constants included from Utils::UrlMagic

Utils::UrlMagic::Max_http_timeout, Utils::UrlMagic::User_agent

Constants included from Utils::DomainRoot

Utils::DomainRoot::File_ccsld, Utils::DomainRoot::File_cctld, Utils::DomainRoot::File_gtld, Utils::DomainRoot::File_tld

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#cidr_2_ips, #file_2_hash, #file_2_list, #get_nameserver, #get_nameservers, #host_2_ip, #host_2_ips, #is_cidr?, #is_fqdn?, #is_ip?, #list_2_file, #reverse_dns_lookup, #sort_ips, #valid_dns_record?, #zone_transferable?

Methods included from Utils::Logger

#wlog

Methods included from Utils::UrlMagic

#create_absolute_url_from_base, #create_absolute_url_from_context, #host_2_url, #is_site?, #is_ssl?, #is_url?, #landing_location, #make_absolute, #normalize_url, #open_page, #redirect_location, #response_code, #response_headers, #url_2_host, #url_2_path, #url_2_port, #url_2_site, #urls_on_same_domain?

Methods included from Utils::DomainRoot

#get_domain_root, #get_domain_root_by_ccsld, #get_domain_root_by_cctld, #get_domain_root_by_tlds, #get_sub_domain, #is_domain_root?, #print_ccsld, #print_cctld, #print_gtld

Constructor Details

#initialize(params = {}) ⇒ GeoIPTracker

Set default instance variables



25
26
27
28
# File 'lib/wmap/geoip_tracker.rb', line 25

def initialize (params = {})		
	@verbose=params.fetch(:verbose, false)
	@db=params.fetch(:db, Db_city)
end

Instance Attribute Details

#dbObject

Returns the value of attribute db.



16
17
18
# File 'lib/wmap/geoip_tracker.rb', line 16

def db
  @db
end

#verboseObject

Returns the value of attribute verbose.



16
17
18
# File 'lib/wmap/geoip_tracker.rb', line 16

def verbose
  @verbose
end

Instance Method Details

#asn(object) ⇒ Object

Wrapper for the Ruby GeoIP ASN class - return data structure below on successful lookup Struct.new(:number, :asn)



61
62
63
64
65
66
67
68
69
70
71
# 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

#city(object) ⇒ Object Also known as: query

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)



32
33
34
35
36
37
38
39
40
41
42
# 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

#country(object) ⇒ Object

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)



47
48
49
50
51
52
53
54
55
56
57
# 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