mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-23 00:59:18 +02:00
14 lines
No EOL
459 B
Rust
14 lines
No EOL
459 B
Rust
use ip2location::{DB, Record};
|
|
|
|
pub fn ip_lookup(ip: &str) -> String {
|
|
let database_path = "resources/IP2LOCATION-LITE-DB5.IPV6.BIN/IP2LOCATION-LITE-DB5.IPV6.BIN";
|
|
|
|
let mut db = DB::from_file(database_path).unwrap();
|
|
|
|
let geo_info = db.ip_lookup(ip.parse().unwrap()).unwrap();
|
|
|
|
let record = if let Record::LocationDb(rec) = geo_info {
|
|
Some(rec)
|
|
} else { None };
|
|
return record.unwrap().country.unwrap().short_name.to_string();
|
|
} |