internetdata 2.16.1 → 2.18.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.
- checksums.yaml +4 -4
- data/README.md +18 -5
- data/lib/internetdata/api/database_v2_api.rb +1 -1
- data/lib/internetdata/api_client.rb +1 -1
- data/lib/internetdata/api_error.rb +1 -1
- data/lib/internetdata/api_model_base.rb +1 -1
- data/lib/internetdata/client.rb +77 -41
- data/lib/internetdata/configuration.rb +1 -1
- data/lib/internetdata/middleware/condition.rb +13 -2
- data/lib/internetdata/middleware/core.rb +61 -5
- data/lib/internetdata/models/abuse_contact.rb +8 -8
- data/lib/internetdata/models/asn.rb +1 -1
- data/lib/internetdata/models/asn_hosted_domains.rb +2 -2
- data/lib/internetdata/models/asn_lookup_response.rb +18 -18
- data/lib/internetdata/models/asn_prefix.rb +2 -2
- data/lib/internetdata/models/batch_lookup_error.rb +1 -1
- data/lib/internetdata/models/bit_torrent_detail.rb +3 -3
- data/lib/internetdata/models/bot_detail.rb +3 -3
- data/lib/internetdata/models/carrier_detail.rb +1 -1
- data/lib/internetdata/models/class_detail.rb +2 -2
- data/lib/internetdata/models/client_registration.rb +1 -1
- data/lib/internetdata/models/cohosted_domains.rb +2 -2
- data/lib/internetdata/models/company.rb +3 -3
- data/lib/internetdata/models/database.rb +1 -1
- data/lib/internetdata/models/database_checksums_response.rb +1 -1
- data/lib/internetdata/models/database_format.rb +1 -1
- data/lib/internetdata/models/database_list.rb +1 -1
- data/lib/internetdata/models/database_metadata.rb +1 -1
- data/lib/internetdata/models/database_metadata_column.rb +1 -1
- data/lib/internetdata/models/database_version.rb +1 -1
- data/lib/internetdata/models/db_checksums.rb +1 -1
- data/lib/internetdata/models/device_authorization.rb +1 -1
- data/lib/internetdata/models/disposable_detail.rb +3 -3
- data/lib/internetdata/models/dns_address_record.rb +2 -2
- data/lib/internetdata/models/dns_cname_record.rb +2 -2
- data/lib/internetdata/models/dns_mx_record.rb +2 -2
- data/lib/internetdata/models/dns_ns_record.rb +2 -2
- data/lib/internetdata/models/dns_resolver_detail.rb +3 -3
- data/lib/internetdata/models/domain_backlinks.rb +2 -2
- data/lib/internetdata/models/domain_dns.rb +2 -2
- data/lib/internetdata/models/domain_host.rb +1 -1
- data/lib/internetdata/models/domain_ip_range.rb +1 -1
- data/lib/internetdata/models/domain_ip_ranges.rb +2 -2
- data/lib/internetdata/models/domain_lookup_response.rb +4 -4
- data/lib/internetdata/models/domain_redirects.rb +2 -2
- data/lib/internetdata/models/domain_web.rb +3 -3
- data/lib/internetdata/models/domain_web_links.rb +1 -1
- data/lib/internetdata/models/download.rb +1 -1
- data/lib/internetdata/models/download_list.rb +1 -1
- data/lib/internetdata/models/entitlement.rb +1 -1
- data/lib/internetdata/models/entitlement_apikey.rb +1 -1
- data/lib/internetdata/models/entitlement_plan.rb +2 -2
- data/lib/internetdata/models/entitlement_usage.rb +3 -3
- data/lib/internetdata/models/error_envelope.rb +1 -1
- data/lib/internetdata/models/hosted_domains.rb +2 -2
- data/lib/internetdata/models/location.rb +11 -11
- data/lib/internetdata/models/lookup_response.rb +23 -23
- data/lib/internetdata/models/oauth_metadata.rb +1 -1
- data/lib/internetdata/models/proxy_detail.rb +3 -3
- data/lib/internetdata/models/pubproxy_detail.rb +2 -2
- data/lib/internetdata/models/rwhois.rb +2 -2
- data/lib/internetdata/models/satellite_detail.rb +1 -1
- data/lib/internetdata/models/smtp_detail.rb +3 -3
- data/lib/internetdata/models/ssh_detail.rb +3 -3
- data/lib/internetdata/models/standing.rb +1 -1
- data/lib/internetdata/models/token_response.rb +1 -1
- data/lib/internetdata/models/user_agent_verdict.rb +1 -1
- data/lib/internetdata/models/web_detail.rb +3 -3
- data/lib/internetdata/models/whois.rb +2 -2
- data/lib/internetdata/result.rb +13 -0
- data/lib/internetdata/transport.rb +29 -9
- data/lib/internetdata/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f63c40928f788a73898f6528f4d83c7f85322a7e5a8030354aec682c20056fee
|
|
4
|
+
data.tar.gz: 910e5da515f77f6a1c6dc5bdabb51d32e28114c53fd7ed0b102b8e26b3424ddc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cd61d4f3e4d69e3e5602c7f584c37d0552e6b3bd27a3debcf46634153776a422fe3f483f0bdc504274c9c26996b14a2083a28bb4acce66f64956c325682ac47e
|
|
7
|
+
data.tar.gz: a628a1be3dc11e2b97439b2b09f4fb8c756589902c924b57321ba66785316d03651005d2de38135ecd472e6538db5798e5d3ed548f8516902cccc506884b6f33
|
data/README.md
CHANGED
|
@@ -38,7 +38,7 @@ result.is_tor # => false
|
|
|
38
38
|
|
|
39
39
|
### With an API key
|
|
40
40
|
|
|
41
|
-
|
|
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 # => "
|
|
80
|
-
acct.plan.name # => "
|
|
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:
|
|
@@ -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
|
|
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/
|
|
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.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.25
|
|
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.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.25
|
|
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.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.25
|
|
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.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.25
|
|
7
7
|
Contact: support@internetdata.io
|
|
8
8
|
Generated by: https://openapi-generator.tech
|
|
9
9
|
Generator version: 7.25.0
|
data/lib/internetdata/client.rb
CHANGED
|
@@ -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(
|
|
119
|
+
hit = @cache&.get(key)
|
|
111
120
|
return hit unless hit.nil?
|
|
112
121
|
|
|
113
|
-
flight, leader = board(
|
|
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(
|
|
120
|
-
return unboard(
|
|
128
|
+
hit = @cache.get(key)
|
|
129
|
+
return unboard(key, flight, :served, hit) unless hit.nil?
|
|
121
130
|
|
|
122
|
-
return lead(
|
|
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 `
|
|
312
|
-
# false] when one is already in flight,
|
|
313
|
-
# lookup is then served, so nothing is shared.
|
|
314
|
-
def board(
|
|
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[
|
|
319
|
-
existing ? [existing, false] : [@flights[
|
|
351
|
+
existing = @flights[key]
|
|
352
|
+
existing ? [existing, false] : [@flights[key] = Flight.new, true]
|
|
320
353
|
end
|
|
321
354
|
end
|
|
322
355
|
|
|
323
|
-
# Takes `
|
|
324
|
-
def unboard(
|
|
325
|
-
@flights_lock.synchronize { @flights.delete(
|
|
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(
|
|
336
|
-
unboard(
|
|
368
|
+
def lead(key, flight)
|
|
369
|
+
unboard(key, flight, :served, yield)
|
|
337
370
|
rescue Error => e
|
|
338
|
-
unboard(
|
|
371
|
+
unboard(key, flight, :failed, e)
|
|
339
372
|
raise
|
|
340
373
|
ensure
|
|
341
|
-
unboard(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.25
|
|
7
7
|
Contact: support@internetdata.io
|
|
8
8
|
Generated by: https://openapi-generator.tech
|
|
9
9
|
Generator version: 7.25.0
|
|
@@ -16,7 +16,14 @@ module InternetData
|
|
|
16
16
|
#
|
|
17
17
|
# A value may be a scalar (equality, strings without regard to case), an
|
|
18
18
|
# Array meaning any-of, a Hash of `gte`/`gt`/`lte`/`lt` bounding a number,
|
|
19
|
-
# or a nested condition.
|
|
19
|
+
# or a nested condition. Against a member the answer holds as a list
|
|
20
|
+
# (`pubproxy.protocols`, the `web` rows) a term matches when any element
|
|
21
|
+
# does, and every member of a nested condition must match the same element:
|
|
22
|
+
#
|
|
23
|
+
# { pubproxy: { protocols: 'socks5' } }
|
|
24
|
+
# { web: { port: 443, status_code: { gte: 500 } } }
|
|
25
|
+
#
|
|
26
|
+
# A member set to `false` or `nil` is ignored
|
|
20
27
|
# entirely - a condition states the positive signals you act on, so there is
|
|
21
28
|
# no way to write "block when this is false", which would otherwise read as
|
|
22
29
|
# blocking everybody.
|
|
@@ -110,8 +117,12 @@ module InternetData
|
|
|
110
117
|
|
|
111
118
|
# An ABSENT member arrives here as nil, which is exactly what "not in your
|
|
112
119
|
# plan" looks like. Every branch below must therefore reject it, which is
|
|
113
|
-
# what makes an unserved member fail a match rather than pass it.
|
|
120
|
+
# what makes an unserved member fail a match rather than pass it. A list
|
|
121
|
+
# the answer holds matches when one of its elements does, so an empty
|
|
122
|
+
# list matches nothing.
|
|
114
123
|
def matches_value?(want, got)
|
|
124
|
+
return got.any? { |element| matches_value?(want, element) } if got.is_a?(Array)
|
|
125
|
+
|
|
115
126
|
case want
|
|
116
127
|
when Array then want.any? { |entry| matches_value?(entry, got) }
|
|
117
128
|
when Hash
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.25
|
|
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.
|
|
22
|
+
# The contact. On a paid plan or the trial.
|
|
23
23
|
attr_accessor :name
|
|
24
24
|
|
|
25
|
-
# Its phone number.
|
|
25
|
+
# Its phone number. On a paid plan or the trial.
|
|
26
26
|
attr_accessor :phone
|
|
27
27
|
|
|
28
|
-
# Its postal address.
|
|
28
|
+
# Its postal address. On a paid plan or the trial.
|
|
29
29
|
attr_accessor :address
|
|
30
30
|
|
|
31
|
-
# ISO 3166 country code.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.25
|
|
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.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.25
|
|
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.
|
|
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
|