class MaxMind::GeoIP2::Record::Traits

Contains data for the traits record associated with an IP address.

This record is returned by all location services and databases.

Public Class Methods

new(record) click to toggle source

@!visibility private

Calls superclass method MaxMind::GeoIP2::Record::Abstract::new
# File lib/maxmind/geoip2/record/traits.rb, line 14
def initialize(record)
  super(record)
  if record && !record.key?('network') && record.key?('ip_address') &&
     record.key?('prefix_length')
    ip = IPAddr.new(record['ip_address']).mask(record['prefix_length'])
    # We could use ip.prefix instead of record['prefix_length'], but that
    # method only becomes available in Ruby 2.5+.
    record['network'] = format('%s/%d', ip.to_s, record['prefix_length'])
  end
end

Public Instance Methods

anonymous?() click to toggle source

This is true if the IP address belongs to any sort of anonymous network. This property is only available from GeoIP2 Precision Insights.

@return [Boolean]

# File lib/maxmind/geoip2/record/traits.rb, line 81
def anonymous?
  get('is_anonymous')
end
anonymous_vpn?() click to toggle source

This is true if the IP address is registered to an anonymous VPN provider. If a VPN provider does not register subnets under names associated with them, we will likely only flag their IP ranges using the hosting_provider? property. This property is only available from GeoIP2 Precision Insights.

@return [Boolean]

# File lib/maxmind/geoip2/record/traits.rb, line 92
def anonymous_vpn?
  get('is_anonymous_vpn')
end
autonomous_system_number() click to toggle source

The autonomous system number associated with the IP address. See Wikipedia. This attribute is only available from the City and Insights web service and the GeoIP2 Enterprise database.

@return [Integer, nil]

# File lib/maxmind/geoip2/record/traits.rb, line 31
def autonomous_system_number
  get('autonomous_system_number')
end
autonomous_system_organization() click to toggle source

The organization associated with the registered autonomous system number for the IP address. See Wikipedia. This attribute is only available from the City and Insights web service and the GeoIP2 Enterprise database.

@return [String, nil]

# File lib/maxmind/geoip2/record/traits.rb, line 42
def autonomous_system_organization
  get('autonomous_system_organization')
end
connection_type() click to toggle source

The connection type may take the following values: “Dialup”, “Cable/DSL”, “Corporate”, “Cellular”. Additional values may be added in the future. This attribute is only available in the GeoIP2 Enterprise database.

@return [String, nil]

# File lib/maxmind/geoip2/record/traits.rb, line 52
def connection_type
  get('connection_type')
end
domain() click to toggle source

The second level domain associated with the IP address. This will be something like “example.com” or “example.co.uk”, not “foo.example.com”. This attribute is only available from the City and Insights web service and the GeoIP2 Enterprise database.

@return [String, nil]

# File lib/maxmind/geoip2/record/traits.rb, line 62
def domain
  get('domain')
end
hosting_provider?() click to toggle source

This is true if the IP address belongs to a hosting or VPN provider (see description of the anonymous_vpn? property). This property is only available from GeoIP2 Precision Insights.

@return [Boolean]

# File lib/maxmind/geoip2/record/traits.rb, line 101
def hosting_provider?
  get('is_hosting_provider')
end
ip_address() click to toggle source

The IP address that the data in the model is for. If you performed a “me” lookup against the web service, this will be the externally routable IP address for the system the code is running on. If the system is behind a NAT, this may differ from the IP address locally assigned to it. This attribute is returned by all end points.

@return [String, nil]

# File lib/maxmind/geoip2/record/traits.rb, line 73
def ip_address
  get('ip_address')
end
isp() click to toggle source

The name of the ISP associated with the IP address. This attribute is only available from the City and Insights web services and the GeoIP2 Enterprise database.

@return [String, nil]

# File lib/maxmind/geoip2/record/traits.rb, line 144
def isp
  get('isp')
end
legitimate_proxy?() click to toggle source

This attribute is true if MaxMind believes this IP address to be a legitimate proxy, such as an internal VPN used by a corporation. This attribute is only available in the GeoIP2 Enterprise database.

@return [Boolean]

# File lib/maxmind/geoip2/record/traits.rb, line 110
def legitimate_proxy?
  get('is_legitimate_proxy')
end
network() click to toggle source

The network in CIDR notation associated with the record. In particular, this is the largest network where all of the fields besides ip_address have the same value.

@return [String, nil]

# File lib/maxmind/geoip2/record/traits.rb, line 153
def network
  get('network')
end
organization() click to toggle source

The name of the organization associated with the IP address. This attribute is only available from the City and Insights web services and the GeoIP2 Enterprise database.

@return [String, nil]

# File lib/maxmind/geoip2/record/traits.rb, line 162
def organization
  get('organization')
end
public_proxy?() click to toggle source

This is true if the IP address belongs to a public proxy. This property is only available from GeoIP2 Precision Insights.

@return [Boolean]

# File lib/maxmind/geoip2/record/traits.rb, line 118
def public_proxy?
  get('is_public_proxy')
end
residential_proxy?() click to toggle source

This is true if the IP address is on a suspected anonymizing network and belongs to a residential ISP. This property is only available from GeoIP2 Precision Insights.

@return [Boolean]

# File lib/maxmind/geoip2/record/traits.rb, line 127
def residential_proxy?
  get('is_residential_proxy')
end
static_ip_score() click to toggle source

An indicator of how static or dynamic an IP address is. This property is only available from GeoIP2 Precision Insights.

@return [Float, nil]

# File lib/maxmind/geoip2/record/traits.rb, line 170
def static_ip_score
  get('static_ip_score')
end
tor_exit_node?() click to toggle source

This is true if the IP address is a Tor exit node. This property is only available from GeoIP2 Precision Insights.

@return [Boolean]

# File lib/maxmind/geoip2/record/traits.rb, line 135
def tor_exit_node?
  get('is_tor_exit_node')
end
user_count() click to toggle source

The estimated number of users sharing the IP/network during the past 24 hours. For IPv4, the count is for the individual IP. For IPv6, the count is for the /64 network. This property is only available from GeoIP2 Precision Insights.

@return [Integer, nil]

# File lib/maxmind/geoip2/record/traits.rb, line 180
def user_count
  get('user_count')
end
user_type() click to toggle source

The user type associated with the IP address. This can be one of the following values:

  • business

  • cafe

  • cellular

  • college

  • content_delivery_network

  • dialup

  • government

  • hosting

  • library

  • military

  • residential

  • router

  • school

  • search_engine_spider

  • traveler

This attribute is only available from the Insights web service and the GeoIP2 Enterprise database.

@return [String, nil]

# File lib/maxmind/geoip2/record/traits.rb, line 207
def user_type
  get('user_type')
end