30 lines
672 B
Rust
30 lines
672 B
Rust
use serde::{Deserialize};
|
|
use reqwest::header::{REFERER, USER_AGENT};
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct IpInfo {
|
|
ip: String,
|
|
asn: IpInfoAsn,
|
|
}
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct IpInfoAsn {
|
|
asn: String,
|
|
name: String,
|
|
}
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct IpInfoProvider {
|
|
name: String,
|
|
}
|
|
|
|
pub async fn ipv4_info() -> Result<IpInfo, Box<dyn std::error::Error>> {
|
|
let client = reqwest::Client::new();
|
|
let resp = client.get("https://ipinfo.io/widget")
|
|
.header(REFERER, "https://ipinfo.io/")
|
|
.header(USER_AGENT, "librefi")
|
|
.send()
|
|
.await?
|
|
.json::<IpInfo>()
|
|
.await?;
|
|
Ok(resp)
|
|
}
|