Class: DoroParser::Geoinfo
- Inherits:
-
Object
- Object
- DoroParser::Geoinfo
- Defined in:
- lib/dorothy2/DEM.rb
Constant Summary collapse
- LOCALNET =
"10.10.10.0/24"
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.
-
#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.
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/DEM.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
#asn ⇒ Object (readonly)
Returns the value of attribute asn.
176 177 178 |
# File 'lib/dorothy2/DEM.rb', line 176 def asn @asn end |
#city ⇒ Object (readonly)
Returns the value of attribute city.
177 178 179 |
# File 'lib/dorothy2/DEM.rb', line 177 def city @city end |
#coord ⇒ Object (readonly)
Returns the value of attribute coord.
175 176 177 |
# File 'lib/dorothy2/DEM.rb', line 175 def coord @coord end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
174 175 176 |
# File 'lib/dorothy2/DEM.rb', line 174 def country @country end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
173 174 175 |
# File 'lib/dorothy2/DEM.rb', line 173 def updated @updated end |