Code Monkey home page Code Monkey logo

ipcap's Introduction

๐ŸŒ IPCap

Crates.io docs License

ipcap 0.1.5

 โ–„โ–ˆ     โ–„โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–„  โ–„โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ    โ–„โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ    โ–„โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–„ 
โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ   โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ   โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ 
โ–ˆโ–ˆโ–ˆโ–Œ   โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆ    โ–ˆโ–€    โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ   โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ 
โ–ˆโ–ˆโ–ˆโ–Œ   โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆ          โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ   โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ 
โ–ˆโ–ˆโ–ˆโ–Œ โ–€โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–€  โ–ˆโ–ˆโ–ˆ        โ–€โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–€โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–€  
โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ        โ–ˆโ–ˆโ–ˆ    โ–ˆโ–„    โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ   โ–ˆโ–ˆโ–ˆ        
โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ        โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ   โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆ   โ–ˆโ–ˆโ–ˆ        
โ–ˆโ–€    โ–„โ–ˆโ–ˆโ–ˆโ–ˆโ–€      โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–€    โ–ˆโ–ˆโ–ˆ    โ–ˆโ–€   โ–„โ–ˆโ–ˆโ–ˆโ–ˆโ–€      

๐ŸŒ IPCAP CLI
============

Perform IP lookup from the command line without internet access. Retrieve information
about IP addresses, including details such as city, region, country, location, etc.

๐Ÿ“– Table of Contents

๐Ÿš€ Installation

To install ipcap, use the following Cargo command:

cargo install --locked ipcap --all-features

๐Ÿ“– Download the dataset

Download the city database from the repository using this command:

curl -LS https://raw.githubusercontent.com/wiseaidev/ipcap/main/data/geo_ip_city.dat --create-dirs -o ~/ipcap/geo_ip_city.dat

This will download the data/geo_ip_city.dat from the repository and put it under ~/ipcap/geo_ip_city.dat.

If, for some reason, you decide to change this file location, just set this environment variable to help the CLI read this file. To set the environment variable before running your Rust program, you can do something like:

export IPCAP_FILE_PATH=/your/custom/path/geo_ip_city.dat

Replace /your/custom/path/geo_ip_city.dat with the desired file path. If the environment variable is not set, the program will use the default path (/home/username/ipcap/geo_ip_city.dat).

Note

The dataset was shamelessly taken from the fedora website at https://src.fedoraproject.org/repo/pkgs/GeoIP-GeoLite-data/GeoLiteCity.dat.gz.

About the dataset

The last 600 bytes of this dataset:

  -46   29  -75  -66   42  103   50   56    0   75  111  108  107   97
  116   97    0   55   52   51   49   50   53    0  -31  -24   30   49
  -13   40  103   50   56    0   67  104   97  110  100   97  110  110
   97  103   97  114    0   55   49   50   49   51   55    0 -108  -12
   30  124  -13   40  103   50   56    0   72  111  111  103  104  108
  121    0   55   49   50   49   50   49    0 -100  -11   30  121  -12
   40  103   49   49    0   66  104   97  114  109  111  117  114    0
   49   55   54   51   49   53    0  -44  106   32  -43   36   39  103
   49   48    0   66   97  110  119   97  115   97    0    0  -84  -23
   31    4   38   39  103   49   49    0   68   97  100   97  104  117
    0   49   55   51   48   50   50    0   55   35   32   -3   71   39
  103   50   51    0   82  117  112  110   97  103   97  114    0    0
  -32   48   32  -45   36   39  103   49   57    0   78   97  103   97
  114    0    0  -99 -109   29 -105  -23   38  100   48   52    0   75
  101  109   97  110  103  103  105  115   97  110    0    0   90 -123
   26  -80  -62   43    0    0    0   71   69   79   45   53   51   51
   76   73   84   69   32   50   48   49   54   48   52   48   53   32
   66  117  105  108  100   32   49   32   67  111  112  121  114  105
  103  104  116   32   40   99   41   32   50   48   49   54   32   77
   97  120   77  105  110  100   32   73  110   99   32   65  108  108
   32   82  105  103  104  116  115   32   82  101  115  101  114   -1
   -1   -1    2   52  -67   41

can be interpreted as follows:

^00 Shek Kip Mei       
24 Phayakkhaphum Phisai 44110 _   6+ 70 Yala 95120 
Jt   * 05 Ban Hong   -   * 44 Bang Khla 24110      
* 68 Ban Na   v   * 77 Amnat Charoen 37000    
Mp+ 68 Ban Phru  _z   * 68 Chana 90160  ~   
* 46 Si Racha 20110  y   * 02 Chiang Mai 50250  
W   * 16 Nakhon Sawan 60130      *g28 Kolkata 743125    
1 (g28 Chandannagar 712137    | (g28 Hooghly 712121    
y (g11 Bharmour 176315  j  $'g10 Banwasa      &'g11 Dadahu 173022 
7#  G'g23 Rupnagar   0  $'g19 Nagar       &d04 Kemanggisan  Z    
+   GEO-533LITE 20160405 Build 1 Copyright (c) 2016 MaxMind Inc All Rights Reserved    4

The forth byte from the end of the file, '2', indicates the database type as the GeoLite City database CITY_EDITION_REV1. This dataset provides geolocation information, featuring diverse locations, numeric codes, and associated details. Place names, such as "Shek Kip Mei" and "Chiang Mai," and numeric codes, postal codes, contribute to the dataset's geographical context. Additionally, metadata elements like "GEO-533LITE" and a copyright statement suggest a connection to the MaxMind geolocation database. The dataset aims to offer insights into the geographical distribution of locations and is potentially valuable for geospatial analysis, like this project.

โœจ Features

  • IP address lookup without internet access.
  • Zero API calls for decoding IP addresses.
  • Dataset download and customizable file path.

โŒจ Usage as CLI

Perform IP lookup:

ipcap -t 8.8.8.8

๐Ÿ’ป Usage as Dep

[dependencies]
ipcap = "0.1.5"
use ipcap::geo_ip_reader::GeoIpReader;
use std::fs::File;

fn main() {
    let mut geo_ip = GeoIpReader::<File>::new().unwrap();
    let record = geo_ip.get_record("8.8.8.8");

    println!("{:?}", record);
}

๐ŸŽจ Options

Option Default Value Description
--target "" Set the IP address to lookup with the --target option.

๐Ÿค Contributing

Contributions and feedback are welcome! If you'd like to contribute, report an issue, or suggest an enhancement, please engage with the project on GitHub. Your contributions help improve this CLI for the community.

๐Ÿ“„ License

This project is licensed under the MIT License.

ipcap's People

Contributors

wiseaidev avatar banocean avatar

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.