pub struct GeoipDb { /* private fields */ }
Expand description
A database of IP addresses to country codes.
Implementations§
source§impl GeoipDb
impl GeoipDb
sourcepub fn new_embedded() -> Arc<Self>
pub fn new_embedded() -> Arc<Self>
Make a new GeoipDb
using a compiled-in copy of the GeoIP database.
The returned instance of the database is shared with Arc
across all invocations of this
function in the same program.
sourcepub fn new_from_legacy_format(db_v4: &str, db_v6: &str) -> Result<Self, Error>
pub fn new_from_legacy_format(db_v4: &str, db_v6: &str) -> Result<Self, Error>
Make a new GeoipDb
using provided copies of the v4 and v6 database, in Tor legacy format.
sourcepub fn lookup_country_code(&self, ip: IpAddr) -> Option<&CountryCode>
pub fn lookup_country_code(&self, ip: IpAddr) -> Option<&CountryCode>
Get a 2-letter country code for the given IP address, if this data is available.
sourcepub fn lookup_country_code_multi<I>(&self, ips: I) -> Option<&CountryCode>where
I: IntoIterator<Item = IpAddr>,
pub fn lookup_country_code_multi<I>(&self, ips: I) -> Option<&CountryCode>where
I: IntoIterator<Item = IpAddr>,
Determine a 2-letter country code for a host with multiple IP addresses.
This looks up all of the IP addresses with lookup_country_code
. If the lookups
return different countries, None
is returned. IP addresses that fail to resolve
into a country are ignored if some of the other addresses do resolve successfully.
sourcepub fn lookup_asn(&self, ip: IpAddr) -> Option<u32>
pub fn lookup_asn(&self, ip: IpAddr) -> Option<u32>
Return the ASN the IP address is in, if this data is available.