internetdata 2.9.2 → 2.10.1
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 +146 -9
- data/lib/internetdata/api/database_v2_api.rb +2 -2
- data/lib/internetdata/api_client.rb +2 -2
- data/lib/internetdata/api_error.rb +2 -2
- data/lib/internetdata/api_model_base.rb +2 -2
- data/lib/internetdata/asn_result.rb +107 -0
- data/lib/internetdata/bogon.rb +92 -0
- data/lib/internetdata/bogons.rb +93 -0
- data/lib/internetdata/cache.rb +35 -0
- data/lib/internetdata/client.rb +396 -16
- data/lib/internetdata/configuration.rb +23 -2
- data/lib/internetdata/domain_result.rb +124 -0
- data/lib/internetdata/errors.rb +29 -6
- data/lib/internetdata/models/abuse_contact.rb +236 -0
- data/lib/internetdata/models/asn.rb +294 -0
- data/lib/internetdata/models/asn_lookup_response.rb +405 -0
- data/lib/internetdata/models/asn_prefix.rb +329 -0
- data/lib/internetdata/models/batch_lookup_error.rb +192 -0
- data/lib/internetdata/models/bit_torrent_detail.rb +240 -0
- data/lib/internetdata/models/carrier_detail.rb +188 -0
- data/lib/internetdata/models/class_detail.rb +178 -0
- data/lib/internetdata/models/client_registration.rb +2 -2
- data/lib/internetdata/models/company.rb +213 -0
- data/lib/internetdata/models/database.rb +2 -2
- data/lib/internetdata/models/database_checksums_response.rb +2 -2
- data/lib/internetdata/models/database_format.rb +2 -2
- data/lib/internetdata/models/database_list.rb +2 -2
- data/lib/internetdata/models/database_metadata.rb +2 -2
- data/lib/internetdata/models/database_metadata_column.rb +2 -2
- data/lib/internetdata/models/database_version.rb +2 -2
- data/lib/internetdata/models/db_checksums.rb +2 -2
- data/lib/internetdata/models/device_authorization.rb +2 -2
- data/lib/internetdata/models/disposable_detail.rb +180 -0
- data/lib/internetdata/models/dns_address_record.rb +192 -0
- data/lib/internetdata/models/dns_cname_record.rb +192 -0
- data/lib/internetdata/models/dns_mx_record.rb +219 -0
- data/lib/internetdata/models/dns_ns_record.rb +192 -0
- data/lib/internetdata/models/dns_resolver_detail.rb +198 -0
- data/lib/internetdata/models/domain_dns.rb +279 -0
- data/lib/internetdata/models/domain_ip_range.rb +219 -0
- data/lib/internetdata/models/domain_ip_ranges.rb +276 -0
- data/lib/internetdata/models/domain_lookup_response.rb +376 -0
- data/lib/internetdata/models/download.rb +2 -2
- data/lib/internetdata/models/download_list.rb +2 -2
- data/lib/internetdata/models/entitlement.rb +243 -0
- data/lib/internetdata/models/entitlement_apikey.rb +207 -0
- data/lib/internetdata/models/entitlement_plan.rb +216 -0
- data/lib/internetdata/models/entitlement_usage.rb +259 -0
- data/lib/internetdata/models/error_envelope.rb +2 -2
- data/lib/internetdata/models/hosted_domains.rb +166 -0
- data/lib/internetdata/models/location.rb +509 -0
- data/lib/internetdata/models/lookup_response.rb +897 -0
- data/lib/internetdata/models/oauth_metadata.rb +2 -2
- data/lib/internetdata/models/proxy_detail.rb +208 -0
- data/lib/internetdata/models/pubproxy_detail.rb +210 -0
- data/lib/internetdata/models/rwhois.rb +301 -0
- data/lib/internetdata/models/satellite_detail.rb +208 -0
- data/lib/internetdata/models/smtp_detail.rb +188 -0
- data/lib/internetdata/models/ssh_detail.rb +198 -0
- data/lib/internetdata/models/standing.rb +2 -2
- data/lib/internetdata/models/token_response.rb +2 -2
- data/lib/internetdata/models/web_detail.rb +516 -0
- data/lib/internetdata/models/whois.rb +382 -0
- data/lib/internetdata/oauth_api.rb +1 -1
- data/lib/internetdata/result.rb +431 -0
- data/lib/internetdata/transport.rb +210 -26
- data/lib/internetdata/version.rb +1 -1
- data/lib/internetdata.rb +17 -2
- metadata +58 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8d551a2233a205fbf677c4bab66f4e48970795b8948f5253736e13795e1100e1
|
|
4
|
+
data.tar.gz: 66390534b688de43157024deb0a86b217f681f2649e32f128df5a78358def68c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1874592aab4b4c990fbfc5dd7bab23620c9109fa9eed5c2bb51cf954d52160fb73506a2e52186568b9fcd3f656943145a081c09c1459a51d5a95ac105a4d0a03
|
|
7
|
+
data.tar.gz: 030c478b5e77d67f10ce5b6c0698841732ba35cfe025a546cf003a081b05af02ba4c39b20a1856a6eaf048facb941cdf5fa730c9f8a3582d28848eb3bfb21696
|
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
|
|
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
|
-
|
|
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. `lookup` takes an IP address alone, and raises a `:bad_request` for anything else before sending it.
|
|
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(
|
|
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
|
|
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.
|
|
247
|
+
client.lookup('146.70.116.130')
|
|
122
248
|
rescue InternetData::Error => e
|
|
123
|
-
warn "#{e.kind} #{e.status} #{e.retryable?}: #{e.
|
|
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`. `
|
|
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`
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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,92 @@
|
|
|
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
|
+
# Whether `ip` reads as one IP address; a prefix is not one.
|
|
34
|
+
def address?(ip)
|
|
35
|
+
!parse(ip).nil?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# The IPv4 address an IPv4-mapped IPv6 address (::ffff:a.b.c.d, in any
|
|
39
|
+
# spelling) carries, dotted, and any other address as given. A server
|
|
40
|
+
# listening on :: sees every IPv4 visitor in that form, which read whole is
|
|
41
|
+
# inside ::ffff:0:0/96, so judging it whole would answer every such visitor
|
|
42
|
+
# locally as a bogon. ::a.b.c.d is IPv4-compatible rather than mapped, and
|
|
43
|
+
# stays IPv6: IPAddr#native alone would unwrap that too.
|
|
44
|
+
def unmapped(ip)
|
|
45
|
+
addr = ip.to_s.include?(':') ? parse(ip) : nil
|
|
46
|
+
addr&.ipv4_mapped? ? addr.native.to_s : ip
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# The answer a bogon gets, in the shape the API answers one on a paid plan:
|
|
50
|
+
# every flag present and false, every detail present and empty, the objects
|
|
51
|
+
# every answer carries with every member empty, an empty hostname, and
|
|
52
|
+
# `is_bogon` true.
|
|
53
|
+
#
|
|
54
|
+
# Deliberately that WIDEST shape regardless of your plan, so do not infer
|
|
55
|
+
# which fields your plan includes from a bogon answer.
|
|
56
|
+
def result(ip)
|
|
57
|
+
raw = { 'ip' => ip, 'is_bogon' => true }
|
|
58
|
+
Result::FLAGS.each { |flag| raw[flag] = false }
|
|
59
|
+
Result::DETAILS.each { |detail| raw[detail] = {} }
|
|
60
|
+
Result::DETAIL_LISTS.each { |detail| raw[detail] = [] }
|
|
61
|
+
OBJECTS.each { |name, model| raw[name] = empty(InternetData.const_get(model)) }
|
|
62
|
+
raw['hostname'] = ''
|
|
63
|
+
Result.new(raw)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def empty(model)
|
|
67
|
+
model.openapi_types.to_h { |attr, type| [model.attribute_map[attr].to_s, EMPTY.fetch(type)] }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Parsed on first use rather than at load: a consumer that never looks an
|
|
71
|
+
# address up should not pay for the table.
|
|
72
|
+
def v4
|
|
73
|
+
@v4 ||= Bogons::V4.map { |cidr| IPAddr.new(cidr) }.freeze
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def v6
|
|
77
|
+
@v6 ||= Bogons::V6.map { |cidr| IPAddr.new(cidr) }.freeze
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def parse(ip)
|
|
81
|
+
text = ip.to_s
|
|
82
|
+
# IPAddr accepts a prefix, and "10.0.0.0/8" is not an address.
|
|
83
|
+
return nil if text.include?('/')
|
|
84
|
+
|
|
85
|
+
IPAddr.new(text)
|
|
86
|
+
rescue IPAddr::Error
|
|
87
|
+
nil
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private_class_method :empty, :v4, :v6, :parse
|
|
91
|
+
end
|
|
92
|
+
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
|