Class: Enricher::Encoder
- Inherits:
-
Object
- Object
- Enricher::Encoder
- Defined in:
- lib/enricher/encoder.rb
Class Method Summary collapse
- .asn(ip) ⇒ Object
- .asn_company(ip) ⇒ Object
- .aton(a) ⇒ Object
- .bogon?(ip) ⇒ Boolean
- .bogon_type(bogon_sym = :ipv4) ⇒ Object
- .cc3(ip) ⇒ Object
- .cdn?(hostname) ⇒ Boolean
- .encode(ip) ⇒ Object
- .encode_online(ip) ⇒ Object
- .latitude(ip) ⇒ Object
- .longitude(ip) ⇒ Object
- .ntoa(a) ⇒ Object
- .rank?(asn) ⇒ Boolean
- .reverse(ip) ⇒ Object
Class Method Details
.asn(ip) ⇒ Object
61 62 63 64 |
# File 'lib/enricher/encoder.rb', line 61 def asn(ip) @@geoASN ||= GeoIP.new("#{Enricher::DATA_PATH}/GeoIPASNum.dat") return @@geoASN.asn(ip).number rescue "--" end |
.asn_company(ip) ⇒ Object
66 67 68 69 |
# File 'lib/enricher/encoder.rb', line 66 def asn_company(ip) @@geoASN ||= GeoIP.new("#{Enricher::DATA_PATH}/GeoIPASNum.dat") return @@geoASN.asn(ip).asn rescue "--" end |
.aton(a) ⇒ Object
39 40 41 |
# File 'lib/enricher/encoder.rb', line 39 def aton(a) IPAddr.new(a).to_i end |
.bogon?(ip) ⇒ Boolean
51 52 53 54 55 |
# File 'lib/enricher/encoder.rb', line 51 def bogon?(ip) @@bogon_type ||= self.bogon_type @@bogon ||= Bogon.new(@@bogon_type) return @@bogon.contains?(ip) end |
.bogon_type(bogon_sym = :ipv4) ⇒ Object
57 58 59 |
# File 'lib/enricher/encoder.rb', line 57 def bogon_type(bogon_sym=:ipv4) bogon_sym end |
.cc3(ip) ⇒ Object
71 72 73 74 |
# File 'lib/enricher/encoder.rb', line 71 def cc3(ip) @@geoCoder ||= GeoIP.new("#{Enricher::DATA_PATH}/GeoIP.dat") return @@geoCoder.country(ip).country_code3 end |
.cdn?(hostname) ⇒ Boolean
91 92 93 |
# File 'lib/enricher/encoder.rb', line 91 def cdn?(hostname) return Enricher::CDN.contains?(hostname) end |
.encode(ip) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/enricher/encoder.rb', line 9 def encode(ip) @@geoASN ||= GeoIP.new("#{Enricher::DATA_PATH}/GeoIPASNum.dat") @@geoCoder ||= GeoIP.new("#{Enricher::DATA_PATH}/GeoIP.dat") @@geoCoderCity ||= GeoIP.new("#{Enricher::DATA_PATH}/GeoLiteCity.dat") @@res ||= Enricher::Resolver.new @@bogon_type ||= self.bogon_type @@bogon ||= Bogon.new(@@bogon_type) asn = @@geoASN.asn(ip).number rescue "--" {:ip => IPAddr.new(ip).to_i, :asn => asn, :asn_rank => Enricher::BGPRanking.rank?(asn), :geoip => @@geoCoder.country(ip).country_code3, :bogon => @@bogon.contains?(ip)} end |
.encode_online(ip) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/enricher/encoder.rb', line 24 def encode_online(ip) @@geoASN ||= GeoIP.new("#{Enricher::DATA_PATH}/GeoIPASNum.dat") @@geoCoder ||= GeoIP.new("#{Enricher::DATA_PATH}/GeoIP.dat") @@geoCoderCity ||= GeoIP.new("#{Enricher::DATA_PATH}/GeoLiteCity.dat") @@res ||= Enricher::Resolver.new @@bogon_type ||= self.bogon_type(:live) @@bogon ||= Bogon.new(@@bogon_type) asn = @@geoASN.asn(ip).number rescue "--" reverse_hostname = self.reverse(ip) rescue "" {:ip => IPAddr.new(ip).to_i, :asn => asn, :asn_rank => Enricher::BGPRanking.rank?(asn), :geoip => @@geoCoder.country(ip).country_code3, :bogon => @@bogon.contains?(ip), :reverse => reverse_hostname, :cdn => self.cdn?(reverse_hostname)} end |
.latitude(ip) ⇒ Object
76 77 78 79 |
# File 'lib/enricher/encoder.rb', line 76 def latitude(ip) @@geoCoderCity ||= GeoIP.new("#{Enricher::DATA_PATH}/GeoIP.dat") return @@geoCoderCity.city(ip).latitude end |
.longitude(ip) ⇒ Object
81 82 83 84 |
# File 'lib/enricher/encoder.rb', line 81 def longitude(ip) @@geoCoderCity ||= GeoIP.new("#{Enricher::DATA_PATH}/GeoIP.dat") return @@geoCoderCity.city(ip).longitude end |
.ntoa(a) ⇒ Object
43 44 45 |
# File 'lib/enricher/encoder.rb', line 43 def ntoa(a) IPAddr.new(a, Socket::AF_INET).to_s end |
.rank?(asn) ⇒ Boolean
47 48 49 |
# File 'lib/enricher/encoder.rb', line 47 def rank?(asn) Enricher::BGPRanking.rank?(asn) end |