Class: DoroParser::Geoinfo
- Inherits:
-
Object
- Object
- DoroParser::Geoinfo
- Defined in:
- lib/dorothy2/DEM.rb
Instance Attribute Summary collapse
-
#asn ⇒ Object
readonly
Returns the value of attribute asn.
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#coord ⇒ Object
readonly
Returns the value of attribute coord.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#isp ⇒ Object
readonly
Returns the value of attribute isp.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Instance Method Summary collapse
-
#initialize(ip) ⇒ Geoinfo
constructor
A new instance of Geoinfo.
Constructor Details
#initialize(ip) ⇒ Geoinfo
Returns a new instance of Geoinfo.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/dorothy2/DEM.rb', line 110 def initialize(ip) @updated = 'null' #TODO take the creation file date of the .dat archive #year = geoip.database_info.grep(/(\S+) (\d{4})(\d{2})(\d{2})/){$2} #month = geoip.database_info.grep(/(\S+) (\d{4})(\d{2})(\d{2})/){$3} #day = geoip.database_info.grep(/(\S+) (\d{4})(\d{2})(\d{2})/){$4} #@updated = year.to_s + "/" + month.to_s + "/" + day.to_s localnetwork = IPAddr.new(DoroSettings.sandbox[:network]) if !localnetwork.include?(ip) begin geoip = GeoIP.new(DoroSettings.env[:geoip]) geoasn = GeoIP.new(DoroSettings.env[:geoasn]) if geoip.country(ip) @city = geoip.country(ip).city_name.force_encoding('UTF-8').gsub(/"|'|\\/, "-") #xcode bug ->>> ") @country = geoip.country(ip).country_code2 @coord = geoip.country(ip).latitude.to_s.gsub(/\(|\)/,'') + "," + geoip.country(ip).longitude.to_s.gsub(/\(|\)/,'') else @city, @country, @coord = "null", "null", "null" end @asn = (geoasn.asn(ip) ? geoasn.asn(ip).as_num[2..-1] : "null" ) @isp = "null" if File.exists?(DoroSettings.env[:geoisp]) geoisp = GeoIP.new(DoroSettings.env[:geoisp]) @isp = geoisp.isp(ip) ? geoisp.isp(ip) : "null" end rescue => e LOGGER_PARSER.fatal "GEO", "Error while fetching GeoIP dat file for IP: " + ip LOGGER_PARSER.fatal "GEO", e.inspect LOGGER_PARSER.fatal "GEO" ,e.backtrace @city, @country, @coord, @asn, @isp = "null", "null", "null", "null", "null" end else @city, @country, @coord, @asn, @isp = "null", "null", "null", "null", "null" end end |
Instance Attribute Details
#asn ⇒ Object (readonly)
Returns the value of attribute asn.
103 104 105 |
# File 'lib/dorothy2/DEM.rb', line 103 def asn @asn end |
#city ⇒ Object (readonly)
Returns the value of attribute city.
105 106 107 |
# File 'lib/dorothy2/DEM.rb', line 105 def city @city end |
#coord ⇒ Object (readonly)
Returns the value of attribute coord.
102 103 104 |
# File 'lib/dorothy2/DEM.rb', line 102 def coord @coord end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
101 102 103 |
# File 'lib/dorothy2/DEM.rb', line 101 def country @country end |
#isp ⇒ Object (readonly)
Returns the value of attribute isp.
104 105 106 |
# File 'lib/dorothy2/DEM.rb', line 104 def isp @isp end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
100 101 102 |
# File 'lib/dorothy2/DEM.rb', line 100 def updated @updated end |