module NginxTail::RemoteAddr

Public Class Methods

to_city_s(remote_addr) click to toggle source
# File lib/ntail/remote_addr.rb, line 28
def self.to_city_s(remote_addr)
  record = if defined? GeoIP # ie. if the optional GeoIP gem is installed
    if File.exists?('/usr/share/GeoIP/GeoIPCity.dat') # ie. if the GeoIP city database is installed
      GeoIP.new('/usr/share/GeoIP/GeoIPCity.dat').city(remote_addr)
    end
  end
  record ? record[7] : 'N/A'
end
to_country_s(remote_addr) click to toggle source
# File lib/ntail/remote_addr.rb, line 19
def self.to_country_s(remote_addr)
  record = if defined? GeoIP # ie. if the optional GeoIP gem is installed
    if File.exists?('/usr/share/GeoIP/GeoIP.dat') # ie. if the GeoIP country database is installed
      GeoIP.new('/usr/share/GeoIP/GeoIP.dat').country(remote_addr)
    end
  end
  record ? record[5] : 'N/A'
end
to_host_s(remote_addr) click to toggle source
# File lib/ntail/remote_addr.rb, line 15
def self.to_host_s(remote_addr)
  Socket::getaddrinfo(remote_addr, nil)[0][2]
end

Public Instance Methods

to_city_s() click to toggle source
# File lib/ntail/remote_addr.rb, line 51
def to_city_s()
  self.class.to_city_s(self.remote_addr)
end
to_country_s() click to toggle source
# File lib/ntail/remote_addr.rb, line 47
def to_country_s()
  self.class.to_country_s(self.remote_addr)
end
to_host_s() click to toggle source
# File lib/ntail/remote_addr.rb, line 43
def to_host_s()
  self.class.to_host_s(self.remote_addr)
end