view usertool/src/main.rs @ 33:a28f7484d2fc

Test geoip lookup in usertool
author Lewin Bormann <lbo@spheniscida.de>
date Sat, 16 Jul 2022 10:14:25 -0700
parents acf064f0e934
children 0c5f8caf6736
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("city db");

    let cy: maxminddb::geoip2::City = citydb.lookup(ip).expect("city from ip");
    println!("{:?}", cy);
}