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