You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ff3ba3f
Browse filesBrowse the repository at this point in the historyBrowse files
The VPNDetection client's lookup surface, ported: isBogon on the client and
as Bogon.isBogon, lookup, lookupBatch, myIp and myEntitlement with their
async forms and LookupOptions or BatchOptions, the bogon answer, IPv4-mapped
addresses read as the address they carry, the per-client cache with shared
misses, the batch in chunks of 1000, and a lookup refusal's message read
from its error member. lookupAsn and lookupDomain take lookup's shape and
are neither cached nor batched.
InternetData's own: Result, AsnResult and DomainResult hand back a member
every plan answers as it is and the rest as an Optional, empty when the plan
leaves it out; a list or map left out reads as absent, not empty. lookup
refuses a string that is not an address before sending, since the API
answers an AS or a domain at that path. The client is AutoCloseable, as the
batch and async pool make it, and Caffeine is back for the cache. The emitted
corpus and bogon table come with the code that passes on them.
The official Java client library for the [InternetData](https://internetdata.io) API.
7
7
8
-
The library lists the IP databases your organization is licensed for, tells you what is inside each one, and downloads them.
8
+
It looks up what every InternetData database says about an IP address, an AS or a domain, and lists, describes and downloads the databases your organization is licensed for.
9
9
10
10
## Getting Started
11
11
@@ -25,19 +25,185 @@ Requires Java 17 or newer. HTTP is the JDK's own `java.net.http.HttpClient`, so
25
25
26
26
## Usage
27
27
28
-
Every database endpoint is licensed, so you need an API key carrying the `db.download` scope. Create one in the console, then:
28
+
**No API key needed to start.** Unlimited, the free plan, answers the Tor, relay, anycast, carrier, satellite and service flags, `location` to the country, `asn`, `company`, `hostname` and the abuse email, with no daily or monthly cap, with a key or without one.
29
29
30
30
```java
31
31
importio.internetdata.InternetData;
32
+
importio.internetdata.Result;
32
33
34
+
InternetData client =InternetData.create();
35
+
36
+
Result result = client.lookup("146.70.116.130");
37
+
System.out.println(result.isTor()); // false
38
+
System.out.println(result.location().getCountry()); // the ISO 3166 country code
39
+
System.out.println(result.asn().getName()); // who runs the announcing network
40
+
```
41
+
42
+
Build the client once and keep it. It owns a connection pool, a cache and a thread pool, and it is thread safe.
43
+
44
+
### With an API key
45
+
46
+
Every paid plan answers every field: `is_vpn`, the four proxy flags, `is_hosting` and `is_cdn`, the detail behind each flag, the city and coordinates, whois and more. The plans differ only in how many lookups they include, and a free account tries every field, 100 lookups a day. Create a key in the [console](https://app.internetdata.io), then pass it in:
System.out.println(domain.dns()); // its records, on a paid plan
67
+
```
68
+
69
+
Neither is cached, and both have `CompletableFuture` variants: `lookupAsnAsync` and `lookupDomainAsync`.
70
+
71
+
### Your own address
72
+
73
+
```java
74
+
Result result = client.myIp();
75
+
System.out.println(result.ip()); // the address we saw this call come from
76
+
```
77
+
78
+
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.
79
+
80
+
### Your plan and usage
81
+
82
+
```java
83
+
Entitlement acct = client.myEntitlement();
84
+
System.out.println(acct.getPlan().getKey()); // the plan your key is on
System.out.println(acct.getUsage().getWindowEnd()); // when the allowance resets
87
+
```
88
+
89
+
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. `getHardLimit()` is `null` on an uncapped plan, which is not the same as zero.
90
+
91
+
`myIpAsync()` and `myEntitlementAsync()` return a `CompletableFuture` of the same thing.
92
+
93
+
### Batch lookup
94
+
95
+
Look up as many addresses as you like in one call. 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:
96
+
97
+
```java
98
+
var results = client.lookupBatch(List.of("146.70.116.130", "8.8.8.8", "1.1.1.1"));
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.
110
+
111
+
How many chunks are in flight at once, how many times a failed chunk is retried, and how long each attempt may take are configurable per call:
Build the client once and keep it. It owns a connection pool, and it is thread safe.
147
+
### Private and reserved addresses
37
148
38
-
The database calls hang off `client.database()`, which is where the sibling VPNDetection library keeps the same seven.
149
+
Private, loopback, link-local, documentation and multicast addresses (and their IPv6 equivalents, including the 6to4 and Teredo ranges) are answered by the library itself, so they cost no request and no quota:
150
+
151
+
```java
152
+
Result result = client.lookup("192.168.1.1");
153
+
result.isBogon(); // true
154
+
result.isTor(); // false
155
+
```
39
156
40
-
### What you can see
157
+
The check is available on the client, which is handy when your inputs are addresses anyway:
158
+
159
+
```java
160
+
client.isBogon("10.0.0.1"); // true
161
+
client.isBogon("8.8.8.8"); // false
162
+
```
163
+
164
+
It is also available on its own, if you want it without a client:
165
+
166
+
```java
167
+
import staticio.internetdata.Bogon.isBogon;
168
+
169
+
isBogon("10.0.0.1"); // true
170
+
```
171
+
172
+
### Errors
173
+
174
+
Failures throw an `InternetDataException` carrying a `kind()` and a `retryable()` flag. It is unchecked, so it travels through a stream or a future without being wrapped first:
`kind()` is one of `BAD_REQUEST`, `UNAUTHORIZED`, `FORBIDDEN`, `RATE_LIMITED`, `QUOTA_EXCEEDED`, `SERVER_ERROR` or `NETWORK`. `getMessage()` is the API's own word where it sent one, so a database refusal reads `NOT_LICENSED` or `LICENSE_EXPIRED` rather than "403".
187
+
188
+
Note that `RATE_LIMITED` and `QUOTA_EXCEEDED` both arrive as HTTP 429 and are not the same thing. A rate limit carries `Retry-After`, so retrying later works, and the library retries it for you, as it does 5xx and transport failures; a spent quota needs your allowance raised or the window to roll over, and the library never retries it, nor any other client error.
189
+
190
+
### Timeouts
191
+
192
+
Each attempt at an API call may take 30 seconds, response body included, before it fails as a retryable `NETWORK` error. Change it for the client, or for a single call:
Result result = client.lookup("146.70.116.130", newLookupOptions().requestTimeout(Duration.ofSeconds(2)));
198
+
```
199
+
200
+
The bound is per attempt, so a call that is retried can take longer in total. Database downloads are not bounded by it, since a large one can take minutes.
201
+
202
+
### Databases
203
+
204
+
If your key carries the `db.download` scope, the databases your organization is licensed for are available through `client.database()`, which is where the sibling VPNDetection library keeps the same seven calls.
205
+
206
+
#### What you can see
41
207
42
208
```java
43
209
importio.internetdata.model.Database;
@@ -52,7 +218,7 @@ A license covers a database *family* (`bogon_ip`), while a download names a *ver
52
218
53
219
`getStanding()` is `LICENSED` for a live grant, `EXPIRED` for one whose term has ended, and `UNLICENSED` for a database published but never bought, which is how you discover what else exists.
54
220
55
-
### What is inside one
221
+
####What is inside one
56
222
57
223
```java
58
224
importio.internetdata.model.DatabaseMetadata;
@@ -67,7 +233,7 @@ meta.getSample(); // a few real rows, per format
67
233
68
234
Poll this to decide whether today's build is worth fetching, and to budget a transfer before you start one.
Failures throw an `InternetDataException` carrying a `kind()` and a `retryable()` flag. It is unchecked, so it travels through a stream or a future without being wrapped first:
`kind()` is one of `BAD_REQUEST`, `UNAUTHORIZED`, `FORBIDDEN`, `RATE_LIMITED`, `QUOTA_EXCEEDED`, `SERVER_ERROR` or `NETWORK`. `getMessage()` is the API's own result code where it sent one, so a refusal reads `NOT_LICENSED` or `LICENSE_EXPIRED` rather than "403".
141
-
142
-
`RATE_LIMITED` is a 429 that carries `Retry-After`, and the library retries it for you, as it does 5xx and transport failures. `QUOTA_EXCEEDED` is a 429 without one, which it never retries, and it retries no other client error either. InternetData's database API has no quota, so you won't see `QUOTA_EXCEEDED` from it.
143
-
144
292
### Sign in with OAuth (device flow)
145
293
146
294
A program running on the person's own machine can let them sign in with a browser and pick one of their API keys, instead of asking them to paste it:
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.
192
340
341
+
### Absent is not false
342
+
343
+
Unlimited leaves out `isVpn()`, the four proxy flags, `isHosting()` and `isCdn()`, the detail behind every flag but Tor's and relay's, whois and `hostedDomains()`, and inside `location()` the city, region and coordinates; a free-plan key's answer carries `trialExpired()`, true once its daily trial is spent. Every member a plan may leave out is an `Optional`, where empty means "not in your plan" rather than "checked, and no", and one inside `location()`, `asn()`, `company()` or `abuse()` is null.
344
+
345
+
```java
346
+
result.isVpn().orElse(false); // when you only want the flag
347
+
result.isVpn().isEmpty(); // on Unlimited: not in your plan
348
+
result.trialExpired().orElse(false); // a free-plan key's daily trial is spent
349
+
```
350
+
193
351
## Other Libraries
194
352
195
353
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.
0 commit comments