Skip to content

hidekuno/cidr-lite

Repository files navigation

IP address search tool

Overview

  • Search the CIDR format network address and country code from the IPv4 address.

Build

Requirement

cd ${HOME}
git clone https://github.com/hidekuno/cidr-lite
cd cidr-lite
python3 cidr_create_geoip.py --token ${your_token}
sqlite3 database.cidr '.read init.sql'
sqlite3 database.cidr '.read city.sql'

Test

python3 tests/test_cidr_search.py

Run

python3 cidr_search.py
  • type IP address

image

Run on docker

Requirement

cd ${HOME}
git clone https://github.com/hidekuno/cidr-lite
cd cidr-lite/cli/docker
docker build -t ${yourid}/cidr-lite --file=Dockerfile --build-arg token=${YOUR_TOKEN_ID} .
docker run -it --name cidr-lite ${yourid}/cidr-lite python3 /root/cidr_search.py

fastapi

Requirement

  • fastapi installed.
  • uvicorn installed.
  • databases installed.
  • aiosqlite installed.
  • SQLAlchemy installed.
  • pydantic installed.

Run

cd ${HOME}/cidr_lite
pip3 install "fastapi[all]"
pip3 install databases
pip3 install aiosqlite

python3 -m uvicorn cidr_api:app --reload

search country,ASN,city

curl -v http://localhost:8000/search?ipv4=23.218.95.131

fastapi with MySQL

Requirement

  • docker installed
  • fastapi(0.111.0) installed.
  • SQLAlchemy installed.
  • mysql-connector-python installed.

Build

docker-compose up -d

Test

pytest -v tests/test_cidr_api2.py