SDKs
Markdown

Ruby SDK

Official IPScope server-side client for Ruby 3.1+ (Puma, Sidekiq & Falcon Fiber-safe) (ipscope).

# Install

Install
gem install ipscope

# Quickstart: single, batch & prefix lookups

Pass your API key explicitly or set IPSCOPE_KEY in your environment. Every lookup returns the canonical response schema with geo, network, connection, security and security_extensions.

Ruby
require "ipscope"

client = IpScope::Client.new(api_key: ENV.fetch("IPSCOPE_KEY"))

# 1. Single IPv4 or IPv6 lookup (cached automatically in bounded LRU)
info = client.lookup_ip("198.51.100.7")
puts "#{info.ip} #{info.geo.country_code} AS#{info.network.asn} VPN=#{info.security.is_vpn}"

# 2. Batch lookup (up to 100 IPs; deduplicates & reuses cached entries)
batch = client.lookup_batch(["198.51.100.7", "1.1.1.1", "2606:4700:4700::1111"])
batch.results.each do |record|
  puts "#{record.ip} -> #{record.network.organization}"
end

# 3. Memory-bounded lazy Enumerator for 10,000+ IPs
client.lookup_batch_stream(large_ip_list).each do |chunk|
  chunk.results.each do |record|
    # Constant O(chunk) memory overhead
  end
end

# 4. Network CIDR prefix lookup
prefix = client.lookup_network("198.51.100.0/24")
puts "#{prefix.queried_cidr} -> AS#{prefix.record.asn} (#{prefix.record.organization})"
Responses
application/json

1. Single IPv4/IPv6 lookup response (GET /v1/ip/{ip})

{
  "ip": "198.51.100.7",
  "ip_version": 4,
  "matched_network": "198.51.100.0/24",
  "geo": {
    "country_code": "US",
    "declared_country_code": "US",
    "physical_country_code": "US",
    "is_virtual_location": false,
    "location_type": "physical",
    "confidence": 0.94,
    "subdivision": "Virginia",
    "city": "Ashburn",
    "postal_code": "20147",
    "latitude": 39.0438,
    "longitude": -77.4874,
    "accuracy_radius_km": 10,
    "timezone": "America/New_York"
  },
  "network": {
    "asn": 64501,
    "organization": "Example Cloud LLC"
  },
  "connection": {
    "connection_type": "hosting",
    "is_hosting": true,
    "is_residential": false,
    "is_mobile": false,
    "is_business": false
  },
  "security": {
    "is_vpn": true,
    "is_hosting": true,
    "is_tor_exit": false,
    "is_proxy": false,
    "anonymizer_type": "vpn",
    "confidence": 0.96,
    "reason_codes": [
      "vpn_handshake_confirmed",
      "datacenter_asn_range"
    ]
  },
  "security_extensions": {
    "abuse_velocity_score": 18,
    "is_known_scanner": false,
    "observation_recency_hours": 12,
    "anonymizer_reason": "vpn_handshake_confirmed",
    "threat_level": "medium",
    "abuse_velocity": "low",
    "confidence": 0.96
  },
  "dataset_version": "2026-10-27T00:00:00Z.crawl-1793088000000",
  "updated_at": "2026-10-27T00:00:00Z"
}
application/json

4. Network CIDR prefix lookup response (GET /v1/networks/{prefix}/{length})

{
  "queried_cidr": "198.51.100.0/24",
  "family": 4,
  "dataset_version": "2026-10-27T00:00:00Z.crawl-1793088000000",
  "record": {
    "prefix": "198.51.100.0/24",
    "family": 4,
    "asn": 64501,
    "organization": "Example Cloud LLC",
    "countryCode": "US",
    "city": "Ashburn",
    "locationType": "physical",
    "isVpn": true,
    "isHosting": true,
    "isTorExit": false,
    "isProxy": false,
    "anonymizerType": "vpn"
  }
}

# Architecture & runtime guarantees

  • Zero external gem dependencies (net/http, json, uri, ipaddr stdlib only).
  • Thread- and Fiber-safe bounded LRU cache (Mutex-synchronized Ruby Hash insertion order) safe for multi-threaded Puma and Sidekiq workers.
  • Frozen Data.define / immutable value objects (IpLookupResponse, GeoInfo, SecurityInfo) prevent accidental mutation across threads.

# Reading local MMDB files

If you subscribe to a downloadable database, our .mmdb snapshots open directly in standard MaxMind DB readers with sub-microsecond in-memory lookups:

Ruby (MMDB)
require "maxmind/db"

reader = MaxMind::DB.new("/var/lib/ipscope/ipscope-complete.mmdb", mode: MaxMind::DB::MODE_MEMORY)
record = reader.get("198.51.100.7")
puts record["geo"]["country_code"]

# Plain HTTP fallback

Need to call the REST API without installing a package? Use Ruby’s standard HTTP client directly:

Ruby (HTTP)
require "net/http"
require "json"

uri = URI("https://api.ipscope.io/v1/ip/198.51.100.7")
req = Net::HTTP::Get.new(uri, "Authorization" => "Bearer #{ENV.fetch('IPSCOPE_KEY')}")
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
info = JSON.parse(res.body)