changeset 33:a28f7484d2fc

Test geoip lookup in usertool
author Lewin Bormann <lbo@spheniscida.de>
date Sat, 16 Jul 2022 10:14:25 -0700
parents ebe9dbb5b5ea
children 761e4438e0dd
files usertool/Cargo.toml usertool/src/main.rs
diffstat 2 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/usertool/Cargo.toml	Fri Jul 15 11:23:47 2022 -0700
+++ b/usertool/Cargo.toml	Sat Jul 16 10:14:25 2022 -0700
@@ -6,3 +6,4 @@
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
+maxminddb = "0.23.0"
--- a/usertool/src/main.rs	Fri Jul 15 11:23:47 2022 -0700
+++ b/usertool/src/main.rs	Sat Jul 16 10:14:25 2022 -0700
@@ -1,3 +1,15 @@
+use maxminddb::Reader;
+
+use std::env::args;
+use std::net::IpAddr;
+use std::str::FromStr;
+
 fn main() {
-    println!("Hello, world!");
+    let a = args().collect::<Vec<String>>();
+
+    let ip = IpAddr::from_str(&a[1]).expect("IP address from argument");
+    let citydb = Reader::open_readfile("/usr/share/GeoIP/GeoLite2-City.mmdb").expect("city db");
+
+    let cy: maxminddb::geoip2::City = citydb.lookup(ip).expect("city from ip");
+    println!("{:?}", cy);
 }