mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-23 09:09:18 +02:00
added request logging
This commit is contained in:
parent
41fa898a67
commit
cdcf27b0fa
5 changed files with 223 additions and 13 deletions
14
src/iplookup.rs
Normal file
14
src/iplookup.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
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();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue