Skip to main content

ipscanner/types/
ip.rs

1use serde::{Deserialize, Serialize};
2
3use super::null_default;
4
5/// Response of `GET /v1/vpn/{ip}`.
6#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
7#[serde(default, rename_all = "camelCase")]
8pub struct VpnResponse {
9    pub ip: String,
10    pub is_vpn: bool,
11    pub is_tor: bool,
12    pub network_class: String,
13    pub anonymized: bool,
14    /// The network owner. Null on the Free plan.
15    pub provider: Option<String>,
16    /// The VPN brand when known. Null on the Free plan.
17    pub vpn_provider: Option<String>,
18    pub risk_score: i64,
19    pub evidence: Vec<String>,
20    /// The score breakdown. Null on the Free plan.
21    pub purity: Option<Purity>,
22    /// On a locked answer: how many reasons the withheld breakdown holds.
23    pub deduction_count: Option<i64>,
24    /// Fields nulled because of the plan.
25    pub locked: Vec<String>,
26    /// The plan that unlocks `locked`.
27    pub plan_required: Option<String>,
28}
29
30/// Response of `GET /v1/proxy/{ip}`.
31#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
32#[serde(default, rename_all = "camelCase")]
33pub struct ProxyResponse {
34    pub ip: String,
35    pub is_proxy: bool,
36    pub is_tor: bool,
37    pub network_class: String,
38    pub anonymized: bool,
39    /// The network owner. Null on the Free plan.
40    pub provider: Option<String>,
41    /// The VPN brand when known. Null on the Free plan.
42    pub vpn_provider: Option<String>,
43    pub risk_score: i64,
44    pub evidence: Vec<String>,
45    /// The score breakdown. Null on the Free plan.
46    pub purity: Option<Purity>,
47    /// On a locked answer: how many reasons the withheld breakdown holds.
48    pub deduction_count: Option<i64>,
49    /// Fields nulled because of the plan.
50    pub locked: Vec<String>,
51    /// The plan that unlocks `locked`.
52    pub plan_required: Option<String>,
53}
54
55/// Response of `GET /v1/geo/{ip}`. Precise-location fields are null on the Free plan.
56#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
57#[serde(default, rename_all = "camelCase")]
58pub struct GeolocationResponse {
59    pub ip: String,
60    pub country: String,
61    pub country_code: String,
62    pub city: String,
63    pub region: String,
64    pub postal_code: Option<String>,
65    pub latitude: Option<f64>,
66    pub longitude: Option<f64>,
67    pub timezone: String,
68    pub accuracy_radius: Option<i64>,
69    pub locked: Vec<String>,
70    pub plan_required: Option<String>,
71}
72
73/// Response of `GET /v1/asn/{ip}`.
74#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
75#[serde(default, rename_all = "camelCase")]
76pub struct AsnResponse {
77    pub ip: String,
78    pub asn: String,
79    pub name: String,
80    #[serde(rename = "type")]
81    pub kind: String,
82    pub country: String,
83}
84
85/// Response of `GET /v1/whois/{domain}`. Dates are the registry's raw strings.
86#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
87#[serde(default, rename_all = "camelCase")]
88pub struct WhoisResponse {
89    pub domain: String,
90    pub registrar: String,
91    pub registered_on: String,
92    pub expires_on: String,
93    pub last_updated: String,
94    #[serde(deserialize_with = "null_default")]
95    pub nameservers: Vec<String>,
96    #[serde(deserialize_with = "null_default")]
97    pub status: Vec<String>,
98    pub privacy_protection: bool,
99    /// `ok`, `not_found`, `timeout`, `unavailable` or `unparsed`; set on `GET /v1/whois/{domain}`.
100    pub whois_status: Option<String>,
101}
102
103/// A full lookup, from `POST /v1/ip/lookup` or `GET /v1/demo/{ip}`.
104#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
105#[serde(default, rename_all = "camelCase")]
106pub struct LookupResult {
107    pub target: Target,
108    pub reserved: ReservedRange,
109    pub verdict: Verdict,
110    /// Null on the Free plan.
111    pub purity: Option<Purity>,
112    pub network_class: String,
113    pub is_vpn: bool,
114    pub is_proxy: bool,
115    pub is_tor: bool,
116    pub provider: Option<String>,
117    pub vpn_provider: Option<String>,
118    pub risk_score: i64,
119    pub network_type: Option<String>,
120    pub geo: Option<GeolocationResponse>,
121    pub asn: Option<AsnResponse>,
122    /// Present only when `whois_status` is `ok`.
123    pub whois: Option<WhoisResponse>,
124    /// Set for hostname targets.
125    pub whois_status: Option<String>,
126    pub degraded: Vec<String>,
127    pub at: String,
128    /// On a locked answer: how many reasons the withheld purity holds.
129    pub deduction_count: Option<i64>,
130    pub locked: Vec<String>,
131    pub plan_required: Option<String>,
132}
133
134/// What a lookup target resolved to.
135#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
136#[serde(default, rename_all = "camelCase")]
137pub struct Target {
138    pub raw: String,
139    pub kind: String,
140    pub ip: String,
141    pub hostname: Option<String>,
142    pub network: Option<String>,
143    pub addresses: Option<i64>,
144}
145
146/// Whether the address is in a reserved range.
147#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
148#[serde(default, rename_all = "camelCase")]
149pub struct ReservedRange {
150    pub reserved: bool,
151    pub label: Option<String>,
152    pub detail: Option<String>,
153}
154
155/// The network classification.
156#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
157#[serde(default, rename_all = "camelCase")]
158pub struct Verdict {
159    pub classification: String,
160    pub anonymized: bool,
161    pub confidence: f64,
162    pub method: String,
163    pub evidence: Vec<String>,
164}
165
166/// The purity score and the deductions behind it.
167#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
168#[serde(default, rename_all = "camelCase")]
169pub struct Purity {
170    pub score: i64,
171    pub grade: String,
172    pub verdict: String,
173    #[serde(deserialize_with = "null_default")]
174    pub deductions: Vec<Deduction>,
175}
176
177/// One factor that lowered a purity score.
178#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
179#[serde(default, rename_all = "camelCase")]
180pub struct Deduction {
181    pub factor: String,
182    pub points: i64,
183    pub detail: String,
184}
185
186/// Query parameters for `GET /v1/ip/history`.
187#[derive(Debug, Clone, Default)]
188pub struct HistoryParams {
189    pub limit: Option<u32>,
190    pub before: Option<i64>,
191    pub verdict: Option<String>,
192}
193
194/// Response of `GET /v1/ip/history`.
195#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
196#[serde(default, rename_all = "camelCase")]
197pub struct History {
198    pub events: Vec<HistoryEvent>,
199    /// Cursor for the next page; 0 means there are no more.
200    pub next_before: i64,
201    pub as_of: String,
202}
203
204/// One past lookup.
205#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
206#[serde(default, rename_all = "camelCase")]
207pub struct HistoryEvent {
208    pub id: i64,
209    pub at: String,
210    pub target: String,
211    pub ip: String,
212    pub verdict: String,
213    pub confidence: f64,
214    pub asn: String,
215    pub asn_name: String,
216    pub country: String,
217    pub anonymized: bool,
218    pub source: String,
219}
220
221/// Response of `GET /v1/myip`.
222#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
223#[serde(default, rename_all = "camelCase")]
224pub struct MyIp {
225    pub ipv4: Option<String>,
226    pub ipv6: Option<String>,
227    pub country: String,
228    pub country_code: String,
229    pub city: String,
230    pub region: String,
231    pub postal_code: String,
232    pub latitude: f64,
233    pub longitude: f64,
234    pub timezone: String,
235    pub accuracy_radius: i64,
236    pub asn: String,
237    pub asn_name: String,
238    pub asn_type: String,
239    pub asn_country: String,
240}