Class: DoroParser::Geoinfo

Inherits:
Object
  • Object
show all
Defined in:
lib/dorothy2/do-parsers.rb

Constant Summary collapse

LOCALNET =
"10.10.10.0/24"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip) ⇒ Geoinfo

Returns a new instance of Geoinfo.



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/dorothy2/do-parsers.rb', line 186

def initialize(ip)
	noutf = Iconv.new('US-ASCII//TRANSLIT', 'UTF-8')
	@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(LOCALNET)
	
	if !localnetwork.include?(ip)
		
		begin
			
			geoip = GeoIP.new(DoroSettings.env[:geoip])
			geoasn = GeoIP.new(DoroSettings.env[:geoasn])
			
			if geoip.country(ip)
				@city = noutf.iconv(geoip.country(ip).city_name).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.to_s.grep(/\d+/){$&}	: "null" )	
			
			rescue
			LOGGER_PARSER.fatal "GEO", "Error while fetching GeoIP dat file for IP: " + ip
			LOGGER_PARSER.fatal "GEO", "#{$!}"
			@city, @country, @coord, @asn = "null", "null", "null", "null"		
		end
		
		else 		
		@city, @country, @coord, @asn = "null", "null", "null", "null"		
		
	end
end

Instance Attribute Details

#asnObject (readonly)

Returns the value of attribute asn.



176
177
178
# File 'lib/dorothy2/do-parsers.rb', line 176

def asn
  @asn
end

#cityObject (readonly)

Returns the value of attribute city.



177
178
179
# File 'lib/dorothy2/do-parsers.rb', line 177

def city
  @city
end

#coordObject (readonly)

Returns the value of attribute coord.



175
176
177
# File 'lib/dorothy2/do-parsers.rb', line 175

def coord
  @coord
end

#countryObject (readonly)

Returns the value of attribute country.



174
175
176
# File 'lib/dorothy2/do-parsers.rb', line 174

def country
  @country
end

#updatedObject (readonly)

Returns the value of attribute updated.



173
174
175
# File 'lib/dorothy2/do-parsers.rb', line 173

def updated
  @updated
end