https://github.com/hidekuno/cidr-lite
country search from IP address
https://github.com/hidekuno/cidr-lite
docker fastapi mysql python3 sqlite3
Last synced: about 2 months ago
JSON representation
country search from IP address
- Host: GitHub
- URL: https://github.com/hidekuno/cidr-lite
- Owner: hidekuno
- Created: 2019-10-17T23:01:10.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-11-02T09:05:17.000Z (over 1 year ago)
- Last Synced: 2025-02-13T09:39:01.331Z (over 1 year ago)
- Topics: docker, fastapi, mysql, python3, sqlite3
- Language: Python
- Homepage:
- Size: 82 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
IP address search tool
=================
## Overview
- Search the CIDR format network address and country code from the IPv4 address.
## Build
### Requirement
- account of maxmind.com(https://www.maxmind.com/en/account/login)
- python3 installed.
- sqlite3 installed.
```
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

## Run on docker
### Requirement
- account of maxmind.com(https://www.maxmind.com/en/account/login)
- docker is running.
```
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
```