Mercurial > lbo > hg > analyrics
view usertool/src/main.rs @ 36:0c5f8caf6736
Implement geoip lookups
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 16 Jul 2022 10:45:58 -0700 |
parents | a28f7484d2fc |
children |
line wrap: on
line source
use maxminddb::Reader; use std::env::args; use std::net::IpAddr; use std::str::FromStr; fn main() { 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("country db"); let cy: maxminddb::geoip2::City = citydb.lookup(ip).expect("city from ip"); println!("{:?}", cy); }