Class: RemoteHost
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RemoteHost
- Includes:
- FastTimestamp
- Defined in:
- lib/honeypot/remote_host.rb
Instance Method Summary collapse
- #delayed_geolocate ⇒ Object
- #delayed_lookup_hostname ⇒ Object
- #geolocate ⇒ Object
- #lookup_hostname ⇒ Object
Instance Method Details
#delayed_geolocate ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/honeypot/remote_host.rb', line 53 def delayed_geolocate if (rand(20) == 1 or latitude.blank?) and ( !(:failed_to_geolocate) or (:failed_to_geolocate) < 5.days.ago ) defined?(Delayed::Job) ? send_later(:geolocate) : geolocate end true end |
#delayed_lookup_hostname ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/honeypot/remote_host.rb', line 43 def delayed_lookup_hostname if (rand(20) == 1 or hostname.blank?) and ( !(:failed_to_lookup_hostname) or (:failed_to_lookup_hostname) < 5.days.ago ) defined?(Delayed::Job) ? send_later(:lookup_hostname) : lookup_hostname end true end |
#geolocate ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/honeypot/remote_host.rb', line 18 def geolocate location = Geokit::Geocoders::MultiGeocoder.geocode ip_address # take what we can get if location.success self.latitude = location.lat if location.lat.present? self.longitude = location.lng if location.lng.present? self.country_code = location.country_code if location.country_code.present? # state -> state_name self.state_name = location.state if location.state.present? self.city = location.city if location.city.present? save! end # but only call it a success if we get latitude # this way if we don't, it will check again in 5 days if location.success and location.latitude.present? :failed_to_geolocate else :failed_to_geolocate end rescue :failed_to_geolocate end |
#lookup_hostname ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/honeypot/remote_host.rb', line 6 def lookup_hostname result = Resolv.getname ip_address if result.present? update_attribute :hostname, result :failed_to_lookup_hostname else :failed_to_lookup_hostname end rescue # Resolv::ResolvError :failed_to_lookup_hostname end |