Giter Site home page Giter Site logo

geoip2-rs's Issues

IPv6 not working

I'm using a paid download of GeoIP database. Not sure if it's the correct one because the documentation is awful.

IPv4 works fine.

Here is the link
https://download.maxmind.com/app/geoip_download?edition_id=GeoIP2-City&suffix=tar.gz&license_key=[mykey]

Then I load it, and query it.

let buffer = fs::read(file_name).unwrap();
let static_buffer: &'static [u8] = Box::leak(Box::new(buffer));
let reader = Reader::<City>::from_bytes(static_buffer).unwrap();

Later on

match result.city === Returns None

This works on the NodeJS GeoIP package, so I assume it's an issue with this library?

The IP works with the geo ip tester.
2606:2800:220:1:248:1893:25c8:1946, it's Cali address.

let mut ip = req.remote_addr().to_string();

// For testing local
if ip.contains("127.0.0.1") {
    // ip = "45.88.221.137".to_string();
    ip = "2606:2800:220:1:248:1893:25c8:1946".to_string(); // Is a valid IP from Cali
}

let ip_address: IpAddr = match FromStr::from_str(&ip) {
    Ok(ip) => ip,
    Err(e) => {
        eprintln!("Error parsing ip: {0:?}", e);
        eprint!("Error parsing ip: {0:?}", ip);
        return Err(ApiError {
            message: "Error parsing ip".to_string(),
            status: "error-with-ip".to_string(),
        });
    }
};

let reader = match GEO_IP_CITY.get() {
    Some(reader) => reader,
    None => {
        eprintln!("Error getting GEO_IP_CITY not setup");
        return Err(ApiError {
            message: "GEO_IP_CITY not setup".to_string(),
            status: "error-with-ip".to_string(),
        });
    }
};

let result: geoip2::City = match reader.lookup(ip_address) {
    Ok(result) => result,
    Err(e) => {
        eprintln!("Error getting result from geo-ip: {0:?}", e);
        return Err(ApiError {
            message: "Error getting result from geo-ip".to_string(),
            status: "error-with-ip".to_string(),
        });
    }
};

let city = match result.city {
    Some(city) => city,
    None => {
        eprintln!("Error getting city on result for geo-ip, no city was returned");
        return Err(ApiError {
            message: "Error getting city, required for this action".to_string(),
            status: "error-with-ip".to_string(),
        });
    }
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.