#geo-ip #bindings #low-level #city

geoip-sys

Low-level bindings for the GeoIP library

12 releases

0.0.14 Jul 11, 2021
0.0.13 Feb 18, 2019
0.0.12 Jan 24, 2017
0.0.10 Jan 22, 2016
0.0.3 Dec 17, 2014

#19 in #city

Download history 18/week @ 2024-07-19 30/week @ 2024-07-26 30/week @ 2024-09-20 4/week @ 2024-09-27

54 downloads per month
Used in geoip

ISC license

4KB
65 lines

rust-geoip

This project is no longer maintained, as MaxMind are phasing out libgeoip and the original database format.

Please switch to libgeoip2, maxminddb and the maxminddb crate.

Original documentation follows:

GeoIP bindings for Rust.

Currently only supports:

Installation: use Cargo.

Tested with GeoIP v1.6.9.

Usage:

City Database:

// Open by DBType
let geoip = GeoIp::open_type(DBType::CityEditionRev1, Options::MemoryCache).unwrap();
// Open by Path
let geoip = GeoIp::open(&Path::new("/opt/geoip/GeoLiteCity.dat"),
						Options::MemoryCache)
	.unwrap();
/*
GeoIp {
	info: Ok(
		"GEO-133 20160621 Build 1 Copyright (c) 2016 MaxMind Inc All Rights Re"
	)
}
*/

// Query by IP
let ip = IpAddr::V4("8.8.8.8".parse().unwrap());
let res = geoip.city_info_by_ip(ip).unwrap();
/*
CityInfo {
	country_code: Some(
		"US"
	),
	country_code3: Some(
		"USA"
	),
	country_name: Some(
		"United States"
	),
	region: Some(
		"CA"
	),
	city: Some(
		"Mountain View"
	),
	postal_code: Some(
		"94035"
	),
	latitude: 37.386,
	longitude: -122.0838,
	dma_code: Some(
		807
	),
	area_code: Some(
		650
	),
	continent_code: Some(
		"NA"
	),
	netmask: 24
}
*/

// Get additional information (as compiled in the C library)
let region_name = GeoIp::region_name_by_code("US", "CA");
// Some("California")

// Get time zone inforamtion (as compiled in the C library)
let time_zone = GeoIp::time_zone_by_country_and_region("US", "CA");
// Some("America/Los_Angeles")

AS Database:

// Open by Path
let geoip = GeoIp::open(&Path::new("/opt/geoip/GeoIPASNum.dat"),
						Options::MemoryCache)
	.unwrap();
/*
GeoIp {
	info: Ok(
		"GEO-117 20160627 Build 1 Copyright (c) 2016 MaxMind Inc All Rights Re"
	)
}
*/

// Query by IP
let ip = IpAddr::V4("8.8.8.8".parse().unwrap());
let res = geoip.as_info_by_ip(ip).unwrap();
/*
ASInfo {
	asn: 15169,
	name: "Google Inc.",
	netmask: 24
}
*/

Dependencies

~44KB