use dns_lookup::getnameinfo;
use crate::Service;
use std::net::{IpAddr, SocketAddr};
pub async fn get_network_ip() -> String {
let response = surf::get("http://ifconfig.me/ip").recv_string().await;
match response {
Ok(response) => return response,
Err(_) => {
eprintln!("error connecting to ifconfig.me");
std::process::exit(1);
}
}
}
pub fn get_dns(ip: IpAddr) -> String {
let socket: SocketAddr = (ip, 80).into();
let name = match getnameinfo(&socket, 0) {
Ok(data) => data.0,
Err(e) => {
eprintln!("failed to lookup socket {:?}", e);
std::process::exit(1);
}
};
return name;
}
pub fn match_method(method: &str) -> Service {
match method {
"ipapi" => Service::IpApi,
"ipapico" => Service::IpApiCo,
"ipwhois" => Service::IpWhois,
"freegeoip" => Service::FreeGeoIp,
&_ => panic!("Other method detected"),
}
}