internetdata 2.9.2 → 2.10.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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +146 -9
  3. data/lib/internetdata/api/database_v2_api.rb +2 -2
  4. data/lib/internetdata/api_client.rb +2 -2
  5. data/lib/internetdata/api_error.rb +2 -2
  6. data/lib/internetdata/api_model_base.rb +2 -2
  7. data/lib/internetdata/asn_result.rb +107 -0
  8. data/lib/internetdata/bogon.rb +87 -0
  9. data/lib/internetdata/bogons.rb +93 -0
  10. data/lib/internetdata/cache.rb +35 -0
  11. data/lib/internetdata/client.rb +388 -16
  12. data/lib/internetdata/configuration.rb +23 -2
  13. data/lib/internetdata/domain_result.rb +124 -0
  14. data/lib/internetdata/errors.rb +29 -6
  15. data/lib/internetdata/models/abuse_contact.rb +236 -0
  16. data/lib/internetdata/models/asn.rb +294 -0
  17. data/lib/internetdata/models/asn_lookup_response.rb +405 -0
  18. data/lib/internetdata/models/asn_prefix.rb +329 -0
  19. data/lib/internetdata/models/batch_lookup_error.rb +192 -0
  20. data/lib/internetdata/models/bit_torrent_detail.rb +410 -0
  21. data/lib/internetdata/models/carrier_detail.rb +273 -0
  22. data/lib/internetdata/models/class_detail.rb +246 -0
  23. data/lib/internetdata/models/client_registration.rb +2 -2
  24. data/lib/internetdata/models/company.rb +213 -0
  25. data/lib/internetdata/models/database.rb +2 -2
  26. data/lib/internetdata/models/database_checksums_response.rb +2 -2
  27. data/lib/internetdata/models/database_format.rb +2 -2
  28. data/lib/internetdata/models/database_list.rb +2 -2
  29. data/lib/internetdata/models/database_metadata.rb +2 -2
  30. data/lib/internetdata/models/database_metadata_column.rb +2 -2
  31. data/lib/internetdata/models/database_version.rb +2 -2
  32. data/lib/internetdata/models/db_checksums.rb +2 -2
  33. data/lib/internetdata/models/device_authorization.rb +2 -2
  34. data/lib/internetdata/models/disposable_detail.rb +248 -0
  35. data/lib/internetdata/models/dns_address_record.rb +192 -0
  36. data/lib/internetdata/models/dns_cname_record.rb +192 -0
  37. data/lib/internetdata/models/dns_mx_record.rb +219 -0
  38. data/lib/internetdata/models/dns_ns_record.rb +192 -0
  39. data/lib/internetdata/models/dns_resolver_detail.rb +300 -0
  40. data/lib/internetdata/models/domain_dns.rb +279 -0
  41. data/lib/internetdata/models/domain_ip_range.rb +219 -0
  42. data/lib/internetdata/models/domain_ip_ranges.rb +276 -0
  43. data/lib/internetdata/models/domain_lookup_response.rb +376 -0
  44. data/lib/internetdata/models/download.rb +2 -2
  45. data/lib/internetdata/models/download_list.rb +2 -2
  46. data/lib/internetdata/models/entitlement.rb +243 -0
  47. data/lib/internetdata/models/entitlement_apikey.rb +207 -0
  48. data/lib/internetdata/models/entitlement_plan.rb +216 -0
  49. data/lib/internetdata/models/entitlement_usage.rb +259 -0
  50. data/lib/internetdata/models/error_envelope.rb +2 -2
  51. data/lib/internetdata/models/hosted_domains.rb +166 -0
  52. data/lib/internetdata/models/location.rb +509 -0
  53. data/lib/internetdata/models/lookup_response.rb +897 -0
  54. data/lib/internetdata/models/oauth_metadata.rb +2 -2
  55. data/lib/internetdata/models/proxy_detail.rb +327 -0
  56. data/lib/internetdata/models/pubproxy_detail.rb +329 -0
  57. data/lib/internetdata/models/rwhois.rb +301 -0
  58. data/lib/internetdata/models/satellite_detail.rb +327 -0
  59. data/lib/internetdata/models/smtp_detail.rb +273 -0
  60. data/lib/internetdata/models/ssh_detail.rb +300 -0
  61. data/lib/internetdata/models/standing.rb +2 -2
  62. data/lib/internetdata/models/token_response.rb +2 -2
  63. data/lib/internetdata/models/web_detail.rb +516 -0
  64. data/lib/internetdata/models/whois.rb +382 -0
  65. data/lib/internetdata/oauth_api.rb +1 -1
  66. data/lib/internetdata/result.rb +431 -0
  67. data/lib/internetdata/transport.rb +215 -27
  68. data/lib/internetdata/version.rb +1 -1
  69. data/lib/internetdata.rb +17 -2
  70. metadata +58 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc736c2ce1797031ec77e9b34bae8cd6c0e61fe00a3a271b8cf74f6121e856fb
4
- data.tar.gz: 76abfc9509f2d5dacde0e91ab46b50e4c0f55160d8055ea147860d0a04e78cd5
3
+ metadata.gz: 8682eb2a09e7c95b8a6bafe0c2849783249c6e1cc458722aa4b2b210453a4c5f
4
+ data.tar.gz: 50f5a7facc448be5f76a82db05924ac3b7ceabd1617315e0fc0f786006ada7e9
5
5
  SHA512:
6
- metadata.gz: 0152be182d98b622b99cd04ca300d5541e01dfe158eceaa0901050b5d5a0849f2facea74d9780705e891d517f2e9fb777bab29631addbbba9dbd2a012d2ed1a0
7
- data.tar.gz: 557718e5edbbdc1f724f89136770c0f958d583635ab79a8a18bc035bfe91ecb9071d54349dd1bb81682491f41d6e1f4bf1136c70061027adfc62399c46b079ee
6
+ metadata.gz: ea33930ef4ba1e8e1c70a7154d19fb3f5f75d5e4da63e914182a50db6577df4c642dc8945c3f277969f278b959b1e17d25e253a64de8b2b64c4daa19b355efc4
7
+ data.tar.gz: d7475a144284fb3a2cf63fad78a6c745218e98f103ea1ac2d4fd084475338ace705bb22f9bc6848bbaf445a4865b9901c5535f24cc0ba20e799820be99d3ae52
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  The official Ruby client library for the [InternetData](https://internetdata.io) API.
7
7
 
8
- InternetData publishes IP and ASN databases: geolocation, anonymity, ownership and network data, as gzipped CSV and as MMDB. This library lists the databases your organization is licensed for, tells you what is inside one before you fetch it, downloads it, and verifies the bytes you got.
8
+ InternetData publishes IP and ASN databases: geolocation, anonymity, ownership and network data, as gzipped CSV and as MMDB. This library looks an IP address, an AS or a domain up in all of them at once, and downloads the databases your organization is licensed for.
9
9
 
10
10
  ## Getting Started
11
11
 
@@ -23,11 +23,136 @@ Requires Ruby 3.3 or newer.
23
23
 
24
24
  ## Usage
25
25
 
26
- Every database published today needs an API key carrying the `db.download` scope. The Open databases are licensed to every organization from the start and are free under [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/), and `list` marks them `open`. The rest are licensed by contract, one family at a time: if your organization doesn't have a license yet, [request an evaluation](https://internetdata.io/contact?purpose=evaluation&subject=Evaluation+license). `api_key:` is nevertheless optional - a client built without one sends no `Authorization` header at all, ready for a database served without a license.
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, anycast, carrier, satellite, SSH, SMTP, web, DNS resolver and BitTorrent flags, with a key or without one, limited per address per minute.
27
27
 
28
28
  ```ruby
29
29
  require 'internetdata'
30
30
 
31
+ client = InternetData::Client.new
32
+
33
+ result = client.lookup('146.70.116.130')
34
+ result.location['country'] # => "AT"
35
+ result.asn['name'] # => "M247 Europe SRL"
36
+ result.is_tor # => false
37
+ ```
38
+
39
+ ### With an API key
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, 100 lookups a day. Create a key in the [console](https://app.internetdata.io), then pass it in:
42
+
43
+ ```ruby
44
+ client = InternetData::Client.new(api_key: ENV['INTERNETDATA_API_KEY'])
45
+
46
+ result = client.lookup('146.70.116.130')
47
+ result.is_vpn # => true, on a paid plan
48
+ result.vpn['provider_name'] # => "Mullvad", on a paid plan
49
+ result.location['city'] # => "Vienna", on a paid plan
50
+ ```
51
+
52
+ ### AS and domain lookups
53
+
54
+ ```ruby
55
+ asn = client.lookup_asn(9009) # or 'AS9009'
56
+ asn.name # => "M247 Europe SRL"
57
+ asn.prefixes # what it announces, on a paid plan
58
+
59
+ domain = client.lookup_domain('example.com')
60
+ domain.is_registered # => true
61
+ domain.dns # its records, on a paid plan
62
+ ```
63
+
64
+ Both are sent as you give them, and the API reads `AS9009` and an internationalized domain too. Neither is cached.
65
+
66
+ ### Your own address
67
+
68
+ ```ruby
69
+ result = client.my_ip
70
+ result.ip # => the address we saw this call come from
71
+ ```
72
+
73
+ Same answer `lookup` would give for that address, and the same cost against your allowance. It is deliberately not cached: which address you are is the whole question, and a machine that moves between networks would otherwise be told where it used to be.
74
+
75
+ ### Your plan and usage
76
+
77
+ ```ruby
78
+ acct = client.my_entitlement
79
+ acct.plan.key # => "max"
80
+ acct.usage.requests # => 580
81
+ acct.usage.window_end # => when the allowance resets
82
+ ```
83
+
84
+ Usage counts against the anniversary of your subscription on a paid plan, not the calendar month and not the billing period, and against the UTC day 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.
85
+
86
+ ### Batch lookup
87
+
88
+ 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:
89
+
90
+ ```ruby
91
+ results = client.lookup_batch(['146.70.116.130', '8.8.8.8', '1.1.1.1'])
92
+
93
+ results.each do |ip, result|
94
+ if result.is_a?(InternetData::Error)
95
+ warn "#{ip}: #{result.message}"
96
+ next
97
+ end
98
+ puts "#{ip}: #{result.location['country']}"
99
+ end
100
+ ```
101
+
102
+ Results are keyed by address, in the order you first listed each one, so duplicates in your list collapse into a single entry and one address failing never loses the rest: it carries its error as its value, with the status the API would have given that address on its own.
103
+
104
+ How many chunks are in flight at once, how many times a failed chunk is retried, and how long each chunk's request may take are configurable per call:
105
+
106
+ ```ruby
107
+ results = client.lookup_batch(many_ips, concurrency: 4, retries: 4, timeout: 5)
108
+ ```
109
+
110
+ ### Caching
111
+
112
+ Address lookups are cached by default, so repeat lookups of the same address are free:
113
+
114
+ ```ruby
115
+ client = InternetData::Client.new
116
+
117
+ result = client.lookup('146.70.116.130') # API request
118
+ result2 = client.lookup('146.70.116.130') # no API request, result was cached
119
+ ```
120
+
121
+ You can change the default cache variables (max size, TTL in seconds) on initialization, or even disable it:
122
+
123
+ ```ruby
124
+ client = InternetData::Client.new(cache_max_size: 50_000, cache_ttl: 6 * 60 * 60)
125
+ client_no_cache = InternetData::Client.new(cache: false)
126
+ ```
127
+
128
+ ### Private and reserved addresses
129
+
130
+ Private, loopback, link-local, documentation and multicast addresses (and their IPv6 equivalents, including the 6to4 and Teredo ranges) are answered locally, so they cost no request and no quota. The answer is the one the API gives a bogon on a paid plan, every flag false, whatever your plan:
131
+
132
+ ```ruby
133
+ result = client.lookup('192.168.1.1')
134
+ result.is_bogon # => true
135
+ result.is_vpn # => false
136
+ ```
137
+
138
+ The check is available on the client, which is handy when your inputs are addresses anyway:
139
+
140
+ ```ruby
141
+ client.bogon?('10.0.0.1') # => true
142
+ client.bogon?('8.8.8.8') # => false
143
+ ```
144
+
145
+ It is also on the module itself, if you want it without a client:
146
+
147
+ ```ruby
148
+ InternetData.bogon?('10.0.0.1') # => true
149
+ ```
150
+
151
+ ### Database downloads
152
+
153
+ Every database published today needs an API key carrying the `db.download` scope. The Open databases are licensed to every organization from the start and are free under [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/), and `list` marks them `open`. The rest are licensed by contract, one family at a time: if your organization doesn't have a license yet, [request an evaluation](https://internetdata.io/contact?purpose=evaluation&subject=Evaluation+license).
154
+
155
+ ```ruby
31
156
  client = InternetData::Client.new(api_key: ENV['INTERNETDATA_API_KEY'])
32
157
 
33
158
  client.database.list.each do |database|
@@ -100,15 +225,16 @@ client.database.downloads(limit: 20).each do |attempt|
100
225
  end
101
226
  ```
102
227
 
103
- ### Timeouts
228
+ ### Timeouts and retries
104
229
 
105
230
  ```ruby
106
- client = InternetData::Client.new(api_key: ENV['INTERNETDATA_API_KEY'], timeout: 10)
231
+ client = InternetData::Client.new(timeout: 10, retries: 4)
107
232
 
233
+ result = client.lookup('146.70.116.130', timeout: 2, retries: 0)
108
234
  catalog = client.database.list(timeout: 5)
109
235
  ```
110
236
 
111
- `timeout` is in seconds and bounds each attempt, body included, so a call that is retried can take longer in total. It defaults to 30 seconds, and 0 means no bound. The client's value is the default: from 2.1.0, `list`, `metadata`, `checksums`, `downloads` and `download_url` each take `timeout:` for that call alone. A negative value, anything that isn't a number, and anything past 2147483.647 seconds (the longest curl holds) raise `ArgumentError` where you pass them, before any request.
237
+ `timeout` is in seconds and bounds each attempt, body included, so a call that is retried can take longer in total. It defaults to 30 seconds, and 0 means no bound. The client's values are defaults: `lookup`, `lookup_asn`, `lookup_domain`, `lookup_batch`, `my_ip` and `my_entitlement` each take `timeout:` and `retries:` for that call alone, and `list`, `metadata`, `checksums`, `downloads`, `download_url` and every `client.oauth` method take `timeout:`. A negative value, anything that isn't a number, and anything past 2147483.647 seconds (the longest curl holds) raise `ArgumentError` where you pass them, before any request. So does a `retries` that isn't an Integer from 0, and a `concurrency` that isn't an Integer from 1 given to `Client.new`, which `lookup_batch` refuses as `:bad_request`.
112
238
 
113
239
  `download` and `download_bytes` take no `timeout:` and raise `ArgumentError` if handed one, rather than accepting it and quietly doing nothing: a transfer runs to gigabytes and minutes, so any bound that suits a JSON call would abandon a healthy download. They bound only their connection with the client's value. `download_url` does take one, because minting the link is an ordinary API request - it bounds that request, not whatever you do with the link afterwards.
114
240
 
@@ -118,15 +244,15 @@ Failures raise an `InternetData::Error` carrying a `kind` and a `retryable?` fla
118
244
 
119
245
  ```ruby
120
246
  begin
121
- client.database.download('vpn_ip_v1', 'mmdb', './vpn_ip_v1.mmdb')
247
+ client.lookup('146.70.116.130')
122
248
  rescue InternetData::Error => e
123
- warn "#{e.kind} #{e.status} #{e.retryable?}: #{e.rc}"
249
+ warn "#{e.kind} #{e.status} #{e.retryable?}: #{e.message}"
124
250
  end
125
251
  ```
126
252
 
127
- `kind` is one of `:bad_request`, `:unauthorized`, `:forbidden`, `:rate_limited`, `:quota_exceeded`, `:server_error` or `:network`. `rc` is the API's own result code, such as `NOT_LICENSED` or `LICENSE_EXPIRED`, which is usually the specific thing you want to read.
253
+ `kind` is one of `:bad_request`, `:unauthorized`, `:forbidden`, `:rate_limited`, `:quota_exceeded`, `:server_error` or `:network`. A lookup's `message` is the API's own words; a database call's refusal also carries `rc`, the API's result code, such as `NOT_LICENSED` or `LICENSE_EXPIRED`.
128
254
 
129
- `:rate_limited` is a 429 that carries `Retry-After`, and the library retries it for you, waiting as long as it says, or its own backoff from 250 ms when that's past about 24.8 days. `:quota_exceeded` is a 429 without one, which it never retries. InternetData's database API has no quota, so you won't see `:quota_exceeded` from it.
255
+ Note that `:rate_limited` and `:quota_exceeded` both arrive as HTTP 429 and are not the same thing. A rate limit is when the API faces extreme traffic bursts and so retrying later works; but a spent quota needs your allowance raised or the window to roll over. The library retries rate limits for you, but not if your quota is exceeded. It waits the `Retry-After` the API sent, or its own backoff from 250 ms when that's past about 24.8 days.
130
256
 
131
257
  ### Sign in with OAuth (device flow)
132
258
 
@@ -173,6 +299,17 @@ registration = client.oauth.register(['http://127.0.0.1:8765/callback'], client_
173
299
 
174
300
  Each redirect URI must be https on a public host name, or http on a loopback address, which then matches any port. Nothing is kept until a person approves the client, so an app with no client ID saved can simply register again.
175
301
 
302
+ ### Absent is not false
303
+
304
+ Unlimited leaves out the VPN, proxy, hosting and CDN flags and their detail, 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 daily trial is spent. 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".
305
+
306
+ ```ruby
307
+ result.vpn? # false when absent, for when you only want the flag
308
+ result.included?(:is_vpn) # false on Unlimited: not in your plan
309
+ result.location.key?('city') # false on Unlimited
310
+ result.trial_expired == true # a free-plan key's daily trial is spent
311
+ ```
312
+
176
313
  ## Other Libraries
177
314
 
178
315
  There are official InternetData client libraries available for many languages including PHP, Python, Go, Java, and Ruby. See our GitHub at https://github.com/internetdata for more.
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #InternetData API
3
3
 
4
- #The InternetData API: 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.
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.08
6
+ The version of the OpenAPI document: 2026.11.13
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #InternetData API
3
3
 
4
- #The InternetData API: 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.
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.08
6
+ The version of the OpenAPI document: 2026.11.13
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #InternetData API
3
3
 
4
- #The InternetData API: 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.
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.08
6
+ The version of the OpenAPI document: 2026.11.13
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #InternetData API
3
3
 
4
- #The InternetData API: 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.
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.08
6
+ The version of the OpenAPI document: 2026.11.13
7
7
  Contact: support@internetdata.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InternetData
4
+ # What a lookup of an AS answers.
5
+ #
6
+ # As with {Result}, an absent member is one your plan does not include, and
7
+ # reads as `nil`, never as 0 or an empty string: Unlimited answers the AS's
8
+ # registration (`asn`, `name`, `country`, `registry`, `allocated`, `domain`),
9
+ # and paid plans and the trial add the rest. `whois` and `prefixes` are the
10
+ # wire values with their original string keys.
11
+ class AsnResult
12
+ include Answer
13
+
14
+ # The AS number.
15
+ def asn
16
+ @raw['asn']
17
+ end
18
+
19
+ # Its operator.
20
+ def name
21
+ @raw['name']
22
+ end
23
+
24
+ # The country its registry assigned it to.
25
+ def country
26
+ @raw['country']
27
+ end
28
+
29
+ # The registry that allocated it.
30
+ def registry
31
+ @raw['registry']
32
+ end
33
+
34
+ # When it was allocated.
35
+ def allocated
36
+ @raw['allocated']
37
+ end
38
+
39
+ # Its operator's domain.
40
+ def domain
41
+ @raw['domain']
42
+ end
43
+
44
+ # The kind of network it runs, or nil when your plan does not include it.
45
+ # Paid plans and the trial.
46
+ def type
47
+ @raw['type']
48
+ end
49
+
50
+ # IPv4 addresses it announces. Paid plans and the trial.
51
+ def num_ips
52
+ @raw['num_ips']
53
+ end
54
+
55
+ # IPv4 prefixes it announces. Paid plans and the trial.
56
+ def num_prefixes4
57
+ @raw['num_prefixes4']
58
+ end
59
+
60
+ # IPv6 prefixes it announces. Paid plans and the trial.
61
+ def num_prefixes6
62
+ @raw['num_prefixes6']
63
+ end
64
+
65
+ # Its announcements RPKI calls valid. Paid plans and the trial.
66
+ def rpki_valid
67
+ @raw['rpki_valid']
68
+ end
69
+
70
+ # Its announcements RPKI calls invalid. Paid plans and the trial.
71
+ def rpki_invalid
72
+ @raw['rpki_invalid']
73
+ end
74
+
75
+ # Its announcements with no RPKI record. Paid plans and the trial.
76
+ def rpki_not_found
77
+ @raw['rpki_not_found']
78
+ end
79
+
80
+ # Its ASN Whois record, every column, empty where the registry states
81
+ # nothing. Paid plans and the trial.
82
+ def whois
83
+ @raw['whois']
84
+ end
85
+
86
+ # What it announces, IPv4 then IPv6, up to 20000 a family, each with its
87
+ # RPKI status. Paid plans and the trial.
88
+ def prefixes
89
+ @raw['prefixes']
90
+ end
91
+
92
+ # On answers to a key on the free plan only: false while its organization's
93
+ # daily trial lasts, true once the answer has Unlimited's; nil on any other.
94
+ def trial_expired
95
+ @raw['trial_expired']
96
+ end
97
+
98
+ # `trial_expired` with an absent member read as false.
99
+ def trial_expired?
100
+ @raw['trial_expired'] == true
101
+ end
102
+
103
+ def inspect
104
+ "#<#{self.class} asn=#{asn.inspect} name=#{name.inspect}>"
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ipaddr'
4
+
5
+ module InternetData
6
+ # Addresses that are reserved rather than routed, answered here rather than on
7
+ # the network.
8
+ module Bogon
9
+ # The objects every answer carries, by the spec's model for each. A bogon
10
+ # answers each with every member its model has, empty.
11
+ OBJECTS = {
12
+ 'location' => 'Location', 'asn' => 'Asn', 'company' => 'Company', 'abuse' => 'AbuseContact',
13
+ 'whois' => 'Whois', 'rwhois' => 'Rwhois', 'hosted_domains' => 'HostedDomains'
14
+ }.freeze
15
+
16
+ # A member's empty value, by the type the spec gives it.
17
+ EMPTY = { String: '', Integer: 0, Float: 0, Boolean: false }.freeze
18
+
19
+ module_function
20
+
21
+ # Whether an address is a bogon: private, loopback, link-local,
22
+ # documentation, multicast or otherwise not routable on the public internet,
23
+ # including the IPv6 equivalents and the 6to4 and Teredo ranges that wrap
24
+ # them.
25
+ def bogon?(ip)
26
+ addr = parse(ip)
27
+ return false if addr.nil?
28
+
29
+ addr = addr.native if addr.ipv4_mapped?
30
+ (addr.ipv4? ? v4 : v6).any? { |range| range.include?(addr) }
31
+ end
32
+
33
+ # The IPv4 address an IPv4-mapped IPv6 address (::ffff:a.b.c.d, in any
34
+ # spelling) carries, dotted, and any other address as given. A server
35
+ # listening on :: sees every IPv4 visitor in that form, which read whole is
36
+ # inside ::ffff:0:0/96, so judging it whole would answer every such visitor
37
+ # locally as a bogon. ::a.b.c.d is IPv4-compatible rather than mapped, and
38
+ # stays IPv6: IPAddr#native alone would unwrap that too.
39
+ def unmapped(ip)
40
+ addr = ip.to_s.include?(':') ? parse(ip) : nil
41
+ addr&.ipv4_mapped? ? addr.native.to_s : ip
42
+ end
43
+
44
+ # The answer a bogon gets, in the shape the API answers one on a paid plan:
45
+ # every flag present and false, every detail present and empty, the objects
46
+ # every answer carries with every member empty, an empty hostname, and
47
+ # `is_bogon` true.
48
+ #
49
+ # Deliberately that WIDEST shape regardless of your plan, so do not infer
50
+ # which fields your plan includes from a bogon answer.
51
+ def result(ip)
52
+ raw = { 'ip' => ip, 'is_bogon' => true }
53
+ Result::FLAGS.each { |flag| raw[flag] = false }
54
+ Result::DETAILS.each { |detail| raw[detail] = {} }
55
+ Result::DETAIL_LISTS.each { |detail| raw[detail] = [] }
56
+ OBJECTS.each { |name, model| raw[name] = empty(InternetData.const_get(model)) }
57
+ raw['hostname'] = ''
58
+ Result.new(raw)
59
+ end
60
+
61
+ def empty(model)
62
+ model.openapi_types.to_h { |attr, type| [model.attribute_map[attr].to_s, EMPTY.fetch(type)] }
63
+ end
64
+
65
+ # Parsed on first use rather than at load: a consumer that never looks an
66
+ # address up should not pay for the table.
67
+ def v4
68
+ @v4 ||= Bogons::V4.map { |cidr| IPAddr.new(cidr) }.freeze
69
+ end
70
+
71
+ def v6
72
+ @v6 ||= Bogons::V6.map { |cidr| IPAddr.new(cidr) }.freeze
73
+ end
74
+
75
+ def parse(ip)
76
+ text = ip.to_s
77
+ # IPAddr accepts a prefix, and "10.0.0.0/8" is not an address.
78
+ return nil if text.include?('/')
79
+
80
+ IPAddr.new(text)
81
+ rescue IPAddr::Error
82
+ nil
83
+ end
84
+
85
+ private_class_method :empty, :v4, :v6, :parse
86
+ end
87
+ end
@@ -0,0 +1,93 @@
1
+ # Generated. Do not edit: a regeneration overwrites it.
2
+ # The list is checked against both upstream definitions on every
3
+ # regeneration.
4
+
5
+ module InternetData
6
+ module Bogons
7
+ V4 = [
8
+ '0.0.0.0/8',
9
+ '10.0.0.0/8',
10
+ '100.64.0.0/10',
11
+ '127.0.0.0/8',
12
+ '169.254.0.0/16',
13
+ '172.16.0.0/12',
14
+ '192.0.0.0/24',
15
+ '192.0.2.0/24',
16
+ '192.88.99.2/32',
17
+ '192.168.0.0/16',
18
+ '198.18.0.0/15',
19
+ '198.51.100.0/24',
20
+ '203.0.113.0/24',
21
+ '224.0.0.0/4',
22
+ '255.255.255.255/32',
23
+ '240.0.0.0/4',
24
+ ].freeze
25
+
26
+ V6 = [
27
+ '::/128',
28
+ '::1/128',
29
+ '::ffff:0:0/96',
30
+ '::/96',
31
+ '64:ff9b::/96',
32
+ '64:ff9b:1::/48',
33
+ '100::/64',
34
+ '100:0:0:1::/64',
35
+ '2001:2::/48',
36
+ '2001:10::/28',
37
+ '2001:db8::/32',
38
+ '3fff::/20',
39
+ '5f00::/16',
40
+ 'fc00::/7',
41
+ 'fe80::/10',
42
+ 'fec0::/10',
43
+ 'ff00::/8',
44
+ '2002::/24',
45
+ '2002:a00::/24',
46
+ '2002:6440::/26',
47
+ '2002:7f00::/24',
48
+ '2002:a9fe::/32',
49
+ '2002:ac10::/28',
50
+ '2002:c000::/40',
51
+ '2002:c000:200::/40',
52
+ '2002:c058:6302::/48',
53
+ '2002:c0a8::/32',
54
+ '2002:c612::/31',
55
+ '2002:c633:6400::/40',
56
+ '2002:cb00:7100::/40',
57
+ '2002:e000::/20',
58
+ '2002:ffff:ffff::/48',
59
+ '2002:f000::/20',
60
+ '2001::/40',
61
+ '2001:0:a00::/40',
62
+ '2001:0:6440::/42',
63
+ '2001:0:7f00::/40',
64
+ '2001:0:a9fe::/48',
65
+ '2001:0:ac10::/44',
66
+ '2001:0:c000::/56',
67
+ '2001:0:c000:200::/56',
68
+ '2001:0:c058:6302::/64',
69
+ '2001:0:c0a8::/48',
70
+ '2001:0:c612::/47',
71
+ '2001:0:c633:6400::/56',
72
+ '2001:0:cb00:7100::/56',
73
+ '2001:0:e000::/36',
74
+ '2001:0:ffff:ffff::/64',
75
+ '2001:0:f000::/36',
76
+ '2001:1::/32',
77
+ '2001:2::/31',
78
+ '2001:4::/30',
79
+ '2001:8::/29',
80
+ '2001:20::/27',
81
+ '2001:40::/26',
82
+ '2001:80::/25',
83
+ '2001:100::/24',
84
+ '::/3',
85
+ '4000::/3',
86
+ '6000::/3',
87
+ '8000::/3',
88
+ 'a000::/3',
89
+ 'c000::/3',
90
+ 'e000::/3',
91
+ ].freeze
92
+ end
93
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lru_redux'
4
+
5
+ module InternetData
6
+ # The per-client answer cache.
7
+ #
8
+ # Per instance and never global: two clients with different keys are on
9
+ # different plans and entitled to different fields, so a shared cache would
10
+ # serve one of them the other's shape. Errors are never stored and bogons
11
+ # never reach it.
12
+ class Cache
13
+ def initialize(max_size:, ttl:)
14
+ raise ArgumentError, 'cache_max_size must be positive' unless max_size.to_i.positive?
15
+
16
+ @store = LruRedux::TTL::ThreadSafeCache.new(max_size.to_i, ttl)
17
+ end
18
+
19
+ def get(key)
20
+ @store[key]
21
+ end
22
+
23
+ def set(key, value)
24
+ @store[key] = value
25
+ end
26
+
27
+ def clear
28
+ @store.clear
29
+ end
30
+
31
+ def size
32
+ @store.count
33
+ end
34
+ end
35
+ end