internetdata 2.17.0 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -7
  3. data/lib/internetdata/api/database_v2_api.rb +1 -1
  4. data/lib/internetdata/api_client.rb +1 -1
  5. data/lib/internetdata/api_error.rb +1 -1
  6. data/lib/internetdata/api_model_base.rb +1 -1
  7. data/lib/internetdata/client.rb +77 -41
  8. data/lib/internetdata/configuration.rb +1 -1
  9. data/lib/internetdata/middleware/core.rb +61 -5
  10. data/lib/internetdata/models/abuse_contact.rb +8 -8
  11. data/lib/internetdata/models/asn.rb +2 -19
  12. data/lib/internetdata/models/asn_hosted_domains.rb +2 -2
  13. data/lib/internetdata/models/asn_lookup_response.rb +18 -18
  14. data/lib/internetdata/models/asn_prefix.rb +1 -1
  15. data/lib/internetdata/models/batch_lookup_error.rb +1 -1
  16. data/lib/internetdata/models/bit_torrent_detail.rb +1 -1
  17. data/lib/internetdata/models/bot_detail.rb +1 -1
  18. data/lib/internetdata/models/carrier_detail.rb +1 -1
  19. data/lib/internetdata/models/class_detail.rb +1 -1
  20. data/lib/internetdata/models/client_registration.rb +1 -1
  21. data/lib/internetdata/models/cohosted_domains.rb +2 -2
  22. data/lib/internetdata/models/company.rb +3 -3
  23. data/lib/internetdata/models/database.rb +1 -1
  24. data/lib/internetdata/models/database_checksums_response.rb +1 -1
  25. data/lib/internetdata/models/database_format.rb +1 -1
  26. data/lib/internetdata/models/database_list.rb +1 -1
  27. data/lib/internetdata/models/database_metadata.rb +1 -1
  28. data/lib/internetdata/models/database_metadata_column.rb +1 -1
  29. data/lib/internetdata/models/database_version.rb +1 -1
  30. data/lib/internetdata/models/db_checksums.rb +1 -1
  31. data/lib/internetdata/models/device_authorization.rb +1 -1
  32. data/lib/internetdata/models/disposable_detail.rb +1 -1
  33. data/lib/internetdata/models/dns_address_record.rb +1 -1
  34. data/lib/internetdata/models/dns_cname_record.rb +1 -1
  35. data/lib/internetdata/models/dns_mx_record.rb +1 -1
  36. data/lib/internetdata/models/dns_ns_record.rb +1 -1
  37. data/lib/internetdata/models/dns_resolver_detail.rb +1 -1
  38. data/lib/internetdata/models/domain_backlinks.rb +2 -2
  39. data/lib/internetdata/models/domain_dns.rb +2 -2
  40. data/lib/internetdata/models/domain_host.rb +1 -1
  41. data/lib/internetdata/models/domain_ip_range.rb +1 -1
  42. data/lib/internetdata/models/domain_ip_ranges.rb +2 -2
  43. data/lib/internetdata/models/domain_lookup_response.rb +4 -4
  44. data/lib/internetdata/models/domain_redirects.rb +2 -2
  45. data/lib/internetdata/models/domain_web.rb +2 -2
  46. data/lib/internetdata/models/domain_web_links.rb +1 -1
  47. data/lib/internetdata/models/download.rb +1 -1
  48. data/lib/internetdata/models/download_list.rb +1 -1
  49. data/lib/internetdata/models/entitlement.rb +1 -1
  50. data/lib/internetdata/models/entitlement_apikey.rb +1 -1
  51. data/lib/internetdata/models/entitlement_plan.rb +2 -2
  52. data/lib/internetdata/models/entitlement_usage.rb +3 -3
  53. data/lib/internetdata/models/error_envelope.rb +1 -1
  54. data/lib/internetdata/models/hosted_domains.rb +2 -2
  55. data/lib/internetdata/models/location.rb +11 -11
  56. data/lib/internetdata/models/lookup_response.rb +31 -167
  57. data/lib/internetdata/models/oauth_metadata.rb +1 -1
  58. data/lib/internetdata/models/proxy_detail.rb +1 -1
  59. data/lib/internetdata/models/pubproxy_detail.rb +1 -1
  60. data/lib/internetdata/models/rwhois.rb +2 -2
  61. data/lib/internetdata/models/satellite_detail.rb +1 -1
  62. data/lib/internetdata/models/smtp_detail.rb +1 -1
  63. data/lib/internetdata/models/ssh_detail.rb +1 -1
  64. data/lib/internetdata/models/standing.rb +1 -1
  65. data/lib/internetdata/models/token_response.rb +1 -1
  66. data/lib/internetdata/models/user_agent_verdict.rb +1 -1
  67. data/lib/internetdata/models/web_detail.rb +1 -1
  68. data/lib/internetdata/models/whois.rb +2 -2
  69. data/lib/internetdata/result.rb +30 -12
  70. data/lib/internetdata/transport.rb +45 -14
  71. data/lib/internetdata/version.rb +1 -1
  72. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31f511086e0fded56dd7acc151e7487a56274403000502630df9e6d1a2a0f9dc
4
- data.tar.gz: dde5b198395b5a347fe00d625cb8b47d8f0bc0ec12a010968901b9672bf9d4ff
3
+ metadata.gz: 92a661392112b0c3506212bc4f1b4c7e9a6529b8ac4689f913d5a0ce1b983c23
4
+ data.tar.gz: 7394f3a0965198f3fa7a9a6fa0a23cb58a29a2cdefe5f9f91de33d74a3df76b1
5
5
  SHA512:
6
- metadata.gz: b97e93065fde28b8bbab8dc167780707baa70572be5a3ed60901c0b591af0487fbf475f81a41800ed1018036d871f75c5620de313f9cd458e678515bd30c785c
7
- data.tar.gz: b776712da8cb0aaa5865e6f9ff7435ff5f099a4e7d824a81c9910db2221e87934d824f30cb0b25838bdff2044cf9547e8eb47b10b9bfad35a5b51dee589aa680
6
+ metadata.gz: e7b76ad8b752e8bdc16202863265a662e9d1801a661f6cb9fd44d896ce2855586c61b2fcf99acd936dcd276f3d1560dde5cc6089271e66a1b0c0bdc4a3b6863c
7
+ data.tar.gz: 6a9a22ebaa0b2549859043206ba5d30861818b66f416dec7f4282e4dc441faa3cde786de348c24b9f003a51bc99998603c472024ef1c6cdf8899f43524103a9f
data/README.md CHANGED
@@ -23,7 +23,7 @@ Requires Ruby 3.3 or newer, and libcurl at runtime, which the `curl` package bri
23
23
 
24
24
  ## Usage
25
25
 
26
- **No API key needed to start.** Unlimited, the free plan, answers an address's location, network, company, abuse contact and reverse DNS, and its Tor, relay, bot, anycast, carrier, satellite, SSH, SMTP, web, DNS resolver and BitTorrent flags, with no daily or monthly cap, with a key or without one.
26
+ **No API key needed to start.** Unlimited, the free plan, answers an address's location, network, company, abuse contact and reverse DNS, and its Tor, relay and anycast flags, with no daily or monthly cap, with a key or without one.
27
27
 
28
28
  ```ruby
29
29
  require 'internetdata'
@@ -38,7 +38,7 @@ result.is_tor # => false
38
38
 
39
39
  ### With an API key
40
40
 
41
- Every paid plan answers every field: the VPN, proxy, hosting and CDN flags as well, the detail behind each flag, and an address's city, Whois, RWHOIS and hosted domains. A free account tries every field. Create a key in the [console](https://app.internetdata.io), then pass it in:
41
+ A paid plan answers every field: the VPN, proxy, hosting and CDN flags as well, the detail behind each flag, and an address's city, Whois, RWHOIS and hosted domains. A free account tries every field. Create a key in the [console](https://app.internetdata.io), then pass it in:
42
42
 
43
43
  ```ruby
44
44
  client = InternetData::Client.new(api_key: ENV['INTERNETDATA_API_KEY'])
@@ -76,14 +76,27 @@ Same answer `lookup` would give for that address, and the same cost against your
76
76
 
77
77
  ```ruby
78
78
  acct = client.my_entitlement
79
- acct.plan.key # => "max"
80
- acct.plan.name # => "Max", the name to show
79
+ acct.plan.key # => "data_4"
80
+ acct.plan.name # => "Data", the name to show
81
81
  acct.usage.requests # => 580
82
82
  acct.usage.window_end # => when the allowance resets
83
83
  ```
84
84
 
85
85
  Usage counts against the anniversary of your subscription on a paid plan, not the calendar month and not the billing period, and against its trial on the free plan; it is the same number a lookup is gated on. `hard_limit` is `nil` on an uncapped plan, which is not the same as zero.
86
86
 
87
+ ### Is that crawler who it says it is?
88
+
89
+ Pass the `User-Agent` of the request you are deciding on, and with every field (a paid plan, or a free account's trial) the answer says whose agent it names and whether this address bears that out:
90
+
91
+ ```ruby
92
+ result = client.lookup('66.249.66.1', user_agent: request.user_agent)
93
+ result.user_agent # => {"agent"=>"Googlebot", "kind"=>"bot", "verdict"=>"verified"}
94
+
95
+ results = client.lookup_batch(ips, user_agents: { '66.249.66.1' => request.user_agent })
96
+ ```
97
+
98
+ `verdict` is `verified` where the agent's operator vouches for the address, `spoofed` where it does not, `unverifiable` for a bot nothing published can confirm, and `not_bot` for a browser, an app or a script. `my_ip` takes `user_agent:` too. A batch's `user_agents` is keyed by each address as you list it, and an address with no agent, or an empty one, is looked up plainly. An answer with an agent is cached apart from the address's plain answer and from another agent's. Unlimited's answers, a private address's and a lookup that sent none carry no `user_agent` (`nil`).
99
+
87
100
  ### Batch lookup
88
101
 
89
102
  Look up as many addresses as you like at once. Bogons and cached answers are handled locally, and everything else goes to the batch endpoint in chunks of up to 1000 addresses, in parallel. The batch endpoint needs a paid plan:
@@ -302,7 +315,7 @@ Each redirect URI must be https on a public host name, or http on a loopback add
302
315
 
303
316
  ### Absent is not false
304
317
 
305
- Unlimited leaves out the VPN, proxy, hosting and CDN flags and their detail, `bot`, which names the bot behind `is_bot`, an address's city and the rest of its paid location, its Whois, RWHOIS and hosted domains, and the paid members inside each shared object, such as `abuse['phone']`. A free-plan key's answer carries `trial_expired`, true once its trial is spent. A paid key's carries `cap_reached`, true once its organization's overage cap is reached, when the answer has Unlimited's fields and isn't billed. A field is present when your plan includes it and `nil` when it does not. `nil` means "not in your plan"; `false` means "we checked, and no".
318
+ Unlimited leaves out the VPN, proxy, hosting, CDN, bot, carrier, satellite, SSH, SMTP, web, DNS resolver and BitTorrent flags and their detail (`bot` names the bot behind `is_bot`), an address's city and the rest of its paid location, its Whois, RWHOIS and hosted domains, and the paid members inside each shared object, such as `abuse['phone']`. A free-plan key's answer carries `trial_expired`, true once its trial is spent. A paid key's carries `cap_reached`, true once its organization's overage cap is reached, when the answer has Unlimited's fields and isn't billed. A field is present when your plan includes it and `nil` when it does not. `nil` means "not in your plan"; `false` means "we checked, and no".
306
319
 
307
320
  ```ruby
308
321
  result.vpn? # false when absent, for when you only want the flag
@@ -318,9 +331,9 @@ There are official InternetData client libraries available for many languages in
318
331
 
319
332
  ## About InternetData
320
333
 
321
- Geolocation, anonymity, ownership and network databases for IP addresses and AS numbers, licensed as files you download and query yourself.
334
+ Geolocation, anonymity, ownership, network, service and domain data for any IP address, AS or domain, by API or as databases you download.
322
335
 
323
- [<img src="https://s3.internetdata.io/internetdata-public/brand/mark.svg" alt="InternetData" height="64"/>](https://internetdata.io/)
336
+ [<picture><source media="(prefers-color-scheme: dark)" srcset="https://s3.internetdata.io/internetdata-public/brand/logo-dark.svg"><img src="https://s3.internetdata.io/internetdata-public/brand/logo.svg" alt="InternetData" height="40"/></picture>](https://internetdata.io/)
324
337
 
325
338
  ## License
326
339
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.26
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.26
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.26
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.26
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -89,13 +89,21 @@ module InternetData
89
89
  #
90
90
  # @param retries [Integer, nil] extra attempts, for THIS call only.
91
91
  # @param timeout [Numeric, nil] seconds each attempt may take, for THIS call only.
92
+ # @param user_agent [String, nil] the `User-Agent` of the request you are
93
+ # deciding on. With every field (a paid plan, or the trial) the answer then
94
+ # carries {Result#user_agent}: the agent it names, and whether this address
95
+ # bears that out. An empty one is none. An answer with one is cached apart
96
+ # from the address's plain answer and from another agent's. A bogon is still
97
+ # answered locally, with no `user_agent`.
92
98
  # @raise [Error] `:bad_request`, before any request, for anything but an IP
93
99
  # address: {#lookup_asn} and {#lookup_domain} look an AS and a domain up.
100
+ # @raise [ArgumentError] for a `user_agent` that is not a String.
94
101
  # @return [Result]
95
- def lookup(ip, retries: nil, timeout: nil)
102
+ def lookup(ip, retries: nil, timeout: nil, user_agent: nil)
96
103
  # Here as well as in the transport: a bogon or a cached answer returns before any request.
97
104
  Transport.checked_timeout(timeout) unless timeout.nil?
98
105
  Retries.checked_count(retries) unless retries.nil?
106
+ agent = Transport.checked_user_agent(user_agent)
99
107
  # Judged, cached and sent as the IPv4 address it carries, if it is mapped.
100
108
  ip = Bogon.unmapped(ip)
101
109
  # The API answers an AS or a domain at this path too, as an answer this call
@@ -106,20 +114,21 @@ module InternetData
106
114
  end
107
115
  return Bogon.result(ip) if Bogon.bogon?(ip)
108
116
 
117
+ key = key_of(ip, agent)
109
118
  loop do
110
- hit = @cache&.get(ip)
119
+ hit = @cache&.get(key)
111
120
  return hit unless hit.nil?
112
121
 
113
- flight, leader = board(ip)
114
- return fetch(ip, retries, timeout) if flight.nil?
122
+ flight, leader = board(key)
123
+ return fetch(ip, agent, retries, timeout) if flight.nil?
115
124
 
116
125
  if leader
117
126
  # Read once more now the address is boarded: a leader that landed
118
127
  # between the miss above and boarding has already cached its answer.
119
- hit = @cache.get(ip)
120
- return unboard(ip, flight, :served, hit) unless hit.nil?
128
+ hit = @cache.get(key)
129
+ return unboard(key, flight, :served, hit) unless hit.nil?
121
130
 
122
- return lead(ip, flight) { fetch(ip, retries, timeout) }
131
+ return lead(key, flight) { fetch(ip, agent, retries, timeout) }
123
132
  end
124
133
  state, value = flight.wait
125
134
  return value if state == :served
@@ -167,11 +176,13 @@ module InternetData
167
176
  # this is IS the question: a machine that moves between networks would
168
177
  # otherwise be told where it used to be.
169
178
  #
179
+ # @param user_agent [String, nil] as {#lookup} takes it.
170
180
  # @return [Result]
171
- def my_ip(retries: nil, timeout: nil)
181
+ def my_ip(retries: nil, timeout: nil, user_agent: nil)
172
182
  Retries.checked_count(retries) unless retries.nil?
183
+ agent = Transport.checked_user_agent(user_agent)
173
184
  Retries.with_retries(retries || @retries) do
174
- Transport.lookup_result(@transport.myip_request(timeout: timeout).run)
185
+ Transport.lookup_result(@transport.myip_request(timeout: timeout, user_agent: agent).run)
175
186
  end
176
187
  end
177
188
 
@@ -222,32 +233,47 @@ module InternetData
222
233
  # request, and before a bogon or a cached answer is returned.
223
234
  # @param retries [Integer, nil] extra attempts for a failed chunk, for THIS batch only.
224
235
  # @param timeout [Numeric, nil] seconds each chunk's attempt may take, for THIS batch only.
236
+ # @param user_agents [Hash{String => String}, nil] the `User-Agent` to send
237
+ # with each address, keyed by the address as given in `ips`: as
238
+ # {#lookup}'s `user_agent:`, per address. An address with none, or an empty
239
+ # one, is looked up plainly. Where two spellings of one IPv4-mapped address
240
+ # carry different agents, the first given is sent.
241
+ # @raise [ArgumentError] for `user_agents` that is not a Hash, or an agent in
242
+ # it that is not a String.
225
243
  # @return [Hash{String => Result, Error}] in the order the addresses were given
226
- def lookup_batch(ips, concurrency: nil, retries: nil, timeout: nil)
244
+ def lookup_batch(ips, concurrency: nil, retries: nil, timeout: nil, user_agents: nil)
227
245
  limit = concurrency || @concurrency
228
246
  unless concurrency?(limit)
229
247
  raise Error.new(:bad_request, "concurrency must be an Integer from 1, not #{limit.inspect}")
230
248
  end
231
249
  Transport.checked_timeout(timeout) unless timeout.nil?
232
250
  Retries.checked_count(retries) unless retries.nil?
251
+ unless user_agents.nil? || user_agents.is_a?(Hash)
252
+ raise ArgumentError, "user_agents must be a Hash of address to agent, not #{user_agents.inspect}"
253
+ end
233
254
 
234
255
  # An IPv4-mapped address is sent as the address it carries, once however
235
256
  # many of its spellings were asked, and answered under each one asked.
236
257
  asked = ips.to_a.uniq
258
+ agents = {}
259
+ asked.each do |ip|
260
+ agent = Transport.checked_user_agent(user_agents&.[](ip))
261
+ agents[Bogon.unmapped(ip)] ||= agent unless agent.nil?
262
+ end
237
263
  addresses = asked.map { |ip| Bogon.unmapped(ip) }.uniq
238
264
  answers = {}
239
265
  pending = []
240
266
 
241
267
  addresses.each do |ip|
242
- hit = Bogon.bogon?(ip) ? Bogon.result(ip) : @cache&.get(ip)
268
+ hit = Bogon.bogon?(ip) ? Bogon.result(ip) : @cache&.get(key_of(ip, agents[ip]))
243
269
  hit.nil? ? pending << ip : answers[ip] = hit
244
270
  end
245
271
  # Boarded before any chunk is built, so a lookup arriving meanwhile waits
246
- # for this batch; an address already in flight is not sent again.
272
+ # for this batch; an address and agent already in flight is not sent again.
247
273
  boarded = {}
248
274
  joined = {}
249
275
  pending.each do |ip|
250
- flight, leader = board(ip)
276
+ flight, leader = board(key_of(ip, agents[ip]))
251
277
  if leader == false
252
278
  joined[ip] = flight
253
279
  else
@@ -257,12 +283,12 @@ module InternetData
257
283
  begin
258
284
  unless boarded.empty?
259
285
  chunks = boarded.keys.each_slice(BATCH_MAX).to_a
260
- run_batch(chunks, answers, limit, retries || @retries, timeout, boarded)
286
+ run_batch(chunks, agents, answers, limit, retries || @retries, timeout, boarded)
261
287
  end
262
288
  ensure
263
- boarded.each { |ip, flight| unboard(ip, flight, :abandoned) unless flight.nil? }
289
+ boarded.each { |ip, flight| unboard(key_of(ip, agents[ip]), flight, :abandoned) unless flight.nil? }
264
290
  end
265
- joined.each { |ip, flight| answers[ip] = joined_answer(ip, flight, retries, timeout) }
291
+ joined.each { |ip, flight| answers[ip] = joined_answer(ip, agents[ip], flight, retries, timeout) }
266
292
 
267
293
  # Reinstated in input order: a hydra settles in completion order, and a
268
294
  # caller iterating the hash should see what they passed in.
@@ -277,6 +303,13 @@ module InternetData
277
303
  value.is_a?(Integer) && value >= 1
278
304
  end
279
305
 
306
+ # What an answer is cached and shared under: the address alone, or the
307
+ # address and the agent sent with it, since that answer carries a verdict
308
+ # the plain one does not.
309
+ def key_of(ip, agent)
310
+ agent.nil? ? ip : [ip, agent]
311
+ end
312
+
280
313
  # Concurrent misses for one address share ONE request. The first miss boards
281
314
  # the address and every miss after it, a batch's included, waits on its
282
315
  # Flight.
@@ -308,21 +341,21 @@ module InternetData
308
341
  end
309
342
  end
310
343
 
311
- # [flight, true] when this caller leads the request for `ip`, [flight,
312
- # false] when one is already in flight, and nil without a cache: every
313
- # lookup is then served, so nothing is shared.
314
- def board(ip)
344
+ # [flight, true] when this caller leads the request for `key`, an address
345
+ # or an address and agent, [flight, false] when one is already in flight,
346
+ # and nil without a cache: every lookup is then served, so nothing is shared.
347
+ def board(key)
315
348
  return nil if @cache.nil?
316
349
 
317
350
  @flights_lock.synchronize do
318
- existing = @flights[ip]
319
- existing ? [existing, false] : [@flights[ip] = Flight.new, true]
351
+ existing = @flights[key]
352
+ existing ? [existing, false] : [@flights[key] = Flight.new, true]
320
353
  end
321
354
  end
322
355
 
323
- # Takes `ip` off the board and lands its flight. Returns `value`.
324
- def unboard(ip, flight, state, value = nil)
325
- @flights_lock.synchronize { @flights.delete(ip) if @flights[ip].equal?(flight) }
356
+ # Takes `key` off the board and lands its flight. Returns `value`.
357
+ def unboard(key, flight, state, value = nil)
358
+ @flights_lock.synchronize { @flights.delete(key) if @flights[key].equal?(flight) }
326
359
  flight.land(state, value)
327
360
  value
328
361
  end
@@ -332,39 +365,42 @@ module InternetData
332
365
  # reaches every waiter and is cached for none; and a leader that never
333
366
  # finishes - a killed thread, a Timeout.timeout - abandons the flight, so
334
367
  # its waiters ask again rather than failing with it.
335
- def lead(ip, flight)
336
- unboard(ip, flight, :served, yield)
368
+ def lead(key, flight)
369
+ unboard(key, flight, :served, yield)
337
370
  rescue Error => e
338
- unboard(ip, flight, :failed, e)
371
+ unboard(key, flight, :failed, e)
339
372
  raise
340
373
  ensure
341
- unboard(ip, flight, :abandoned)
374
+ unboard(key, flight, :abandoned)
342
375
  end
343
376
 
344
- def fetch(ip, retries, timeout)
377
+ def fetch(ip, agent, retries, timeout)
345
378
  result = Retries.with_retries(retries || @retries) do
346
- Transport.lookup_result(@transport.lookup_request(ip, timeout: timeout).run)
379
+ Transport.lookup_result(@transport.lookup_request(ip, timeout: timeout, user_agent: agent).run)
347
380
  end
348
- @cache&.set(ip, result)
381
+ @cache&.set(key_of(ip, agent), result)
349
382
  result
350
383
  end
351
384
 
352
385
  # One hydra per call, sized for THIS call. Reusing an instance-level hydra
353
386
  # would silently cap a per-call concurrency at the client's setting, and
354
387
  # would not be safe to drive from two threads either. Each request is one
355
- # chunk of up to 1000 addresses.
356
- def run_batch(chunks, answers, concurrency, retries, timeout, boarded)
388
+ # chunk of up to 1000 addresses, carrying the agents of that chunk's
389
+ # addresses alone.
390
+ def run_batch(chunks, agents, answers, concurrency, retries, timeout, boarded)
357
391
  hydra = Typhoeus::Hydra.new(max_concurrency: concurrency)
358
392
  attempts = Hash.new(0)
359
393
 
360
394
  enqueue = lambda do |chunk|
361
- request = @transport.batch_request(chunk, timeout: timeout)
395
+ sent = chunk.filter_map { |ip| [ip, agents[ip]] if agents.key?(ip) }.to_h
396
+ request = @transport.batch_request(chunk, timeout: timeout, user_agents: sent)
362
397
  request.on_complete do |response|
363
- outcome = settle(chunk, response, attempts, retries, enqueue)
398
+ outcome = settle(chunk, agents, response, attempts, retries, enqueue)
364
399
  outcome&.each do |ip, answer|
365
400
  answers[ip] = answer
366
401
  flight = boarded[ip]
367
- unboard(ip, flight, answer.is_a?(Result) ? :served : :failed, answer) unless flight.nil?
402
+ state = answer.is_a?(Result) ? :served : :failed
403
+ unboard(key_of(ip, agents[ip]), flight, state, answer) unless flight.nil?
368
404
  end
369
405
  end
370
406
  hydra.queue(request)
@@ -378,11 +414,11 @@ module InternetData
378
414
  # chunk-level failure - the call refused, the transport failing, the retries
379
415
  # exhausted - becomes every address's error, exactly as it would have been
380
416
  # had each been looked up alone.
381
- def settle(chunk, response, attempts, retries, enqueue)
417
+ def settle(chunk, agents, response, attempts, retries, enqueue)
382
418
  body = Transport.batch_body(response)
383
419
  chunk.to_h do |ip|
384
420
  answer = batch_answer(ip, body)
385
- @cache&.set(ip, answer) if answer.is_a?(Result)
421
+ @cache&.set(key_of(ip, agents[ip]), answer) if answer.is_a?(Result)
386
422
  [ip, answer]
387
423
  end
388
424
  rescue Error => e
@@ -398,11 +434,11 @@ module InternetData
398
434
 
399
435
  # What a batch takes for an address another call was fetching: that call's
400
436
  # answer or error, or, when its leader never finished, its own lookup.
401
- def joined_answer(ip, flight, retries, timeout)
437
+ def joined_answer(ip, agent, flight, retries, timeout)
402
438
  state, value = flight.wait
403
439
  return value unless state == :abandoned
404
440
 
405
- lookup(ip, retries: retries, timeout: timeout)
441
+ lookup(ip, retries: retries, timeout: timeout, user_agent: agent)
406
442
  rescue Error => e
407
443
  e
408
444
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.26
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -27,14 +27,29 @@ module InternetData
27
27
  DEFAULT_TIMEOUT = 2.5
28
28
  DEFAULT_RETRIES = 0
29
29
 
30
+ # Reads a request's `User-Agent` where the adapter names no reader: Rack's
31
+ # request has `user_agent`, and so do Sinatra's and Hanami's.
32
+ DEFAULT_USER_AGENT = ->(request) { request.user_agent if request.respond_to?(:user_agent) }
33
+
30
34
  # Resolve, classify, decide.
31
35
  class Core
32
36
  # @param default_ip_selector [#call] the framework's own accessor, used
33
37
  # when the caller named none.
34
- def initialize(default_ip_selector, **options)
38
+ # @param user_agent_of [#call] reads the request's own `User-Agent`, which
39
+ # `allow_bots: true` sends with the lookup.
40
+ # @option options [Boolean] :allow_bots (false) send the request's own
41
+ # `User-Agent` with its lookup, and never refuse a request whose answer
42
+ # says `user_agent.verdict` is `verified`, whatever the condition
43
+ # matches; the answer is still attached. An absent or empty header sends
44
+ # none. A keyless client, or a free key past its trial, never gets a
45
+ # verdict, so nothing is let through there, and that is warned of once
46
+ # under `on_missing_field`.
47
+ def initialize(default_ip_selector, user_agent_of = DEFAULT_USER_AGENT, **options)
35
48
  Condition.validate!(options[:block_condition])
36
49
  @condition = options[:block_condition]
37
50
  @selector = options[:ip_selector] || default_ip_selector
51
+ @allow_bots = options.fetch(:allow_bots, false) == true
52
+ @user_agent_of = user_agent_of
38
53
  @fail_closed = options.fetch(:fail_closed, false)
39
54
  @on_missing_field = options.fetch(:on_missing_field, :warn)
40
55
  @skip = options[:skip]
@@ -76,12 +91,14 @@ module InternetData
76
91
  )
77
92
  end
78
93
 
94
+ # A bogon is answered locally, so nothing is sent for it.
95
+ agent = @allow_bots && !Bogon.bogon?(ip) ? user_agent(request) : nil
79
96
  begin
80
- result = @client.lookup(ip, retries: @retries)
97
+ result = @client.lookup(ip, retries: @retries, **(agent ? { user_agent: agent } : {}))
81
98
  rescue InternetData::Error => e
82
99
  return Lookup.new(blocked: @fail_closed, ip: ip, error: e)
83
100
  end
84
- decide(ip, result)
101
+ decide(ip, result, agent)
85
102
  end
86
103
 
87
104
  private
@@ -97,19 +114,35 @@ module InternetData
97
114
  )
98
115
  end
99
116
 
100
- def decide(ip, result)
117
+ # The request's own `User-Agent`, or nil when it sent none or an empty one.
118
+ def user_agent(request)
119
+ agent = @user_agent_of.call(request)
120
+ agent.is_a?(String) && !agent.empty? ? agent : nil
121
+ end
122
+
123
+ def decide(ip, result, agent)
124
+ report_unanswered_agent(result) unless agent.nil?
101
125
  return Lookup.new(blocked: false, ip: ip, result: result) if @condition.nil?
102
126
 
103
127
  report_missing(result)
104
128
  Lookup.new(
105
- blocked: Condition.matches?(@condition, result),
129
+ blocked: Condition.matches?(@condition, result) && !verified?(result),
106
130
  ip: ip,
107
131
  result: result
108
132
  )
109
133
  end
110
134
 
135
+ # Whether `allow_bots` lets this answer through: its agent's operator
136
+ # vouches for the address.
137
+ def verified?(result)
138
+ @allow_bots && result.user_agent.is_a?(Hash) && result.user_agent['verdict'] == 'verified'
139
+ end
140
+
111
141
  def report_missing(result)
112
142
  return if @on_missing_field == :ignore
143
+ # A bogon is answered locally in the widest shape, which carries every
144
+ # member but `user_agent`, and no agent is sent for it.
145
+ return if result.bogon?
113
146
 
114
147
  missing = Condition.missing_members(@condition, result)
115
148
  return if missing.empty?
@@ -117,6 +150,24 @@ module InternetData
117
150
  message = "block_condition names #{missing.join(', ')}, which your plan does not " \
118
151
  'include, so those terms can never match. An absent member means "not in ' \
119
152
  'your plan", not "checked, and no".'
153
+ if missing.include?('user_agent') && !@allow_bots
154
+ message += ' user_agent is answered only to a lookup that sends one, which allow_bots does.'
155
+ end
156
+ report(message)
157
+ end
158
+
159
+ # An agent went with the lookup and the served answer carries no verdict:
160
+ # a keyless client, or a free key past its trial, is never answered one,
161
+ # so allow_bots lets no crawler through.
162
+ def report_unanswered_agent(result)
163
+ return if @on_missing_field == :ignore || result.included?(:user_agent)
164
+
165
+ report('allow_bots sends the request\'s User-Agent, but the answer carries no user_agent ' \
166
+ 'verdict, which your plan does not include, so no crawler is let through. A key on ' \
167
+ 'a paid plan, or on its trial, is answered one.')
168
+ end
169
+
170
+ def report(message)
120
171
  raise ArgumentError, "internetdata: #{message}" if @on_missing_field == :raise
121
172
 
122
173
  warn_once(message)
@@ -147,6 +198,11 @@ module InternetData
147
198
  ->(request) { @view.call(request).framework_ip.call }
148
199
  end
149
200
 
201
+ # The request's own `User-Agent` header, which `allow_bots` sends.
202
+ def user_agent
203
+ ->(request) { @view.call(request).header.call('User-Agent') }
204
+ end
205
+
150
206
  # An address from `X-Forwarded-For`.
151
207
  #
152
208
  # The LEFT-MOST entry (depth 0) is whatever the caller sent, because
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.26
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -19,25 +19,25 @@ module InternetData
19
19
  # Where to report abuse from the address.
20
20
  attr_accessor :email
21
21
 
22
- # The contact. Paid plans and the trial.
22
+ # The contact. On a paid plan or the trial.
23
23
  attr_accessor :name
24
24
 
25
- # Its phone number. Paid plans and the trial.
25
+ # Its phone number. On a paid plan or the trial.
26
26
  attr_accessor :phone
27
27
 
28
- # Its postal address. Paid plans and the trial.
28
+ # Its postal address. On a paid plan or the trial.
29
29
  attr_accessor :address
30
30
 
31
- # ISO 3166 country code. Paid plans and the trial.
31
+ # ISO 3166 country code. On a paid plan or the trial.
32
32
  attr_accessor :country
33
33
 
34
- # The registry block it was derived from. Paid plans and the trial.
34
+ # The registry block it was derived from. On a paid plan or the trial.
35
35
  attr_accessor :network
36
36
 
37
- # ARIN reports the contact answered its yearly validation. Paid plans and the trial.
37
+ # ARIN reports the contact answered its yearly validation. On a paid plan or the trial.
38
38
  attr_accessor :validated
39
39
 
40
- # Since when it has not. Paid plans and the trial.
40
+ # Since when it has not. On a paid plan or the trial.
41
41
  attr_accessor :unvalidated_since
42
42
 
43
43
  # Attribute mapping from ruby-style variable name to JSON key.
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.26
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -25,7 +25,7 @@ module InternetData
25
25
  # Its operator's domain.
26
26
  attr_accessor :domain
27
27
 
28
- # The kind of network it runs.
28
+ # The kind of network it runs. On a paid plan or the trial.
29
29
  attr_accessor :type
30
30
 
31
31
  # The announced prefix covering the address.
@@ -115,8 +115,6 @@ module InternetData
115
115
 
116
116
  if attributes.key?(:'type')
117
117
  self.type = attributes[:'type']
118
- else
119
- self.type = nil
120
118
  end
121
119
 
122
120
  if attributes.key?(:'prefix')
@@ -155,10 +153,6 @@ module InternetData
155
153
  invalid_properties.push('invalid value for "domain", domain cannot be nil.')
156
154
  end
157
155
 
158
- if @type.nil?
159
- invalid_properties.push('invalid value for "type", type cannot be nil.')
160
- end
161
-
162
156
  if @prefix.nil?
163
157
  invalid_properties.push('invalid value for "prefix", prefix cannot be nil.')
164
158
  end
@@ -181,7 +175,6 @@ module InternetData
181
175
  return false if @asn.nil?
182
176
  return false if @name.nil?
183
177
  return false if @domain.nil?
184
- return false if @type.nil?
185
178
  return false if @prefix.nil?
186
179
  return false if @country.nil?
187
180
  return false if @rpki_status.nil?
@@ -218,16 +211,6 @@ module InternetData
218
211
  @domain = domain
219
212
  end
220
213
 
221
- # Custom attribute writer method with validation
222
- # @param [Object] type Value to be assigned
223
- def type=(type)
224
- if type.nil?
225
- fail ArgumentError, 'type cannot be nil'
226
- end
227
-
228
- @type = type
229
- end
230
-
231
214
  # Custom attribute writer method with validation
232
215
  # @param [Object] prefix Value to be assigned
233
216
  def prefix=(prefix)
@@ -3,7 +3,7 @@
3
3
 
4
4
  #The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.26
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -14,7 +14,7 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module InternetData
17
- # From ASN Hosted Domains: how many registered domains the AS hosts, and the 10 most popular. Its database lists up to 1,000 an AS. Paid plans and the trial.
17
+ # From ASN Hosted Domains: how many registered domains the AS hosts, and the 10 most popular. Its database lists up to 1,000 an AS. On a paid plan or the trial.
18
18
  class AsnHostedDomains < ApiModelBase
19
19
  # How many registered domains resolve to an address the AS announces.
20
20
  attr_accessor :total