1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use reqwest::Error;
use serde::Deserialize;

#[derive(Deserialize, Debug)]
pub struct IPData {
    #[serde(rename = "as")]
    pub asn: String,
    pub city: String,
    pub country: String,
    #[serde(rename = "countryCode")]
    pub country_code: String,
    pub isp: String,
    pub lat: f64,
    pub lon: f64,
    pub org: String,
    pub query: String,
    pub region: String,
    #[serde(rename = "regionName")]
    pub region_name: String,
    pub status: String,
    pub timezone: String,
    pub zip: String,
}

pub fn get() -> Result<IPData, Error> {
    let url = "http://ip-api.com/json";

    let json: IPData = reqwest::get(url)?.json()?;

    return Ok(json);
}