ip-lookup

Crates.ioip-lookup
lib.rsip-lookup
version0.1.3
created_at2025-07-29 03:07:49.857422+00
updated_at2025-08-01 15:55:01.727532+00
descriptionA unified IP geolocation query library using multiple free public providers.
homepage
repositoryhttps://github.com/rfshub/ip-lookup
max_upload_size
id1771851
size57,217
Canmi (canmi21)

documentation

https://docs.rs/ip-lookup

README

IP Lookup

A unified IP geolocation query library using multiple free public providers.

Documentation License: MIT

Overview

The ip-lookup crate provides a simple and unified interface to query IP geolocation information from multiple free public providers. It supports various providers like IpApi, IpInfo, IpSb, and more, allowing you to retrieve details such as country, city, coordinates, and network information for a given IP address.

Installation

Add the following to your Cargo.toml:

[dependencies]
ip-lookup = "0.1.0"

Usage

The crate provides functions to get the public IP address and query geolocation data using different providers. Below is an example of how to use the library:

use ip_lookup::{get_public_ip_addr, lookup, LookupProvider, LookupResult};

fn main() {
    // Get the public IP address
    if let Some(ip) = get_public_ip_addr() {
        println!("Public IP: {}", ip);
    }

    // Query geolocation data using a specific provider
    if let Some(result) = lookup(LookupProvider::IpApi) {
        println!("Geolocation Data: {:?}", result);
    }

    // Iterate over all available providers
    for provider in LookupProvider::all() {
        if let Some(result) = lookup(*provider) {
            println!("Provider: {:?}, Data: {:?}", provider, result);
        }
    }
}

Example Output

The lookup function returns an Option<LookupResult>, where LookupResult contains detailed geolocation information. An example response might look like this:

{
  "country": {
    "city": "Singapore",
    "code": "SG",
    "zip": "535225",
    "timezone": "Asia/Singapore"
  },
  "location": {
    "latitude": 1.3371,
    "longitude": 103.8946
  },
  "connection": {
    "is_proxy": false,
    "is_tor": false,
    "is_crawler": false,
    "is_datacenter": true,
    "is_vpn": false
  },
  "network": {
    "ip": "91.243.81.209",
    "isp": "G-Core Labs S.A.",
    "org": "G-Core Labs S.A.",
    "asn": "AS199524 G-Core Labs S.A."
  }
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

Commit count: 0

cargo fmt