adulau/mmdb-server
GitHub: adulau/mmdb-server
mmdb-server 是一个基于 Python 的高性能 IP 地理位置查询 API 服务,支持 MaxMind DB 格式,可同时查询 IPv4/IPv6 的国家信息和 AS 编号。
Stars: 195 | Forks: 24
# mmdb-server
mmdb-server 是一个开源的快速 API 服务器,用于查询 IP 地址的地理位置和 AS 编号。该服务器可与任何 [MaxMind DB 文件格式](https://maxmind.github.io/MaxMind-DB/) 或相同格式的文件一起使用。
mmdb-server 包含一个免费且开放的 [GeoOpen-Country 数据库](https://data.public.lu/fr/datasets/geo-open-ip-address-geolocation-per-country-in-mmdb-format/),适用于 IPv4 和 IPv6 地址。文件 [GeoOpen-Country](https://cra.circl.lu/opendata/geo-open/mmdb-country/) 和 [GeoOpen-Country-ASN](https://cra.circl.lu/opendata/geo-open/mmdb-country-asn/) 是根据 AS 发布及其各自的 whois 记录定期生成的。
# 安装
## 常规方式
运行带有 poetry 的 mmdb-server 需要 Python 3.10+。
- `curl -sSL https://install.python-poetry.org | python3 -`
- 注销并重新登录
- `poetry install`
- `cp ./etc/server.conf.sample ./etc/server.conf`
- `cd ./db; bash update.sh; cd ..` (以获取最新版本的 GeoOpen 数据库)
- `poetry run serve`
## Docker
- `docker build -t mmdb-server:latest .`
- `docker run -d -p 8000:8000 --name mmdb-server mmdb-server:latest`
# 使用方法
## 查询 IP 地址
`curl -s http://127.0.0.1:8000/geolookup/188.65.220.25 | jq .`
```
[
{
"country": {
"iso_code": "BE"
},
"meta": {
"description": {
"en": "Geo Open MMDB database - https://github.com/adulau/mmdb-server"
},
"build_db": "2022-02-05 11:37:33",
"db_source": "GeoOpen-Country",
"nb_nodes": 1159974
},
"ip": "188.65.220.25",
"country_info": {
"Country": "Belgium",
"Alpha-2 code": "BE",
"Alpha-3 code": "BEL",
"Numeric code": "56",
"Latitude (average)": "50.8333",
"Longitude (average)": "4"
}
},
{
"country": {
"iso_code": "BE",
"AutonomousSystemNumber": "49677",
"AutonomousSystemOrganization": "MAEHDROS-AS"
},
"meta": {
"description": {
"en": "Geo Open MMDB database - https://github.com/adulau/mmdb-server"
},
"build_db": "2022-02-06 10:30:25",
"db_source": "GeoOpen-Country-ASN",
"nb_nodes": 1159815
},
"ip": "188.65.220.25",
"country_info": {
"Country": "Belgium",
"Alpha-2 code": "BE",
"Alpha-3 code": "BEL",
"Numeric code": "56",
"Latitude (average)": "50.8333",
"Longitude (average)": "4"
}
}
]
```
`$ curl -s http://127.0.0.1:8000/geolookup/2a02:21d0::68:69:25 | jq .`
```
[
{
"country": {
"iso_code": "BE"
},
"meta": {
"description": {
"en": "Geo Open MMDB database - https://github.com/adulau/mmdb-server"
},
"build_db": "2022-02-05 11:37:33",
"db_source": "GeoOpen-Country",
"nb_nodes": 1159974
},
"ip": "2a02:21d0::68:69:25",
"country_info": {
"Country": "Belgium",
"Alpha-2 code": "BE",
"Alpha-3 code": "BEL",
"Numeric code": "56",
"Latitude (average)": "50.8333",
"Longitude (average)": "4"
}
},
{
"country": {
"iso_code": "BE",
"AutonomousSystemNumber": "49677",
"AutonomousSystemOrganization": "MAEHDROS-AS"
},
"meta": {
"description": {
"en": "Geo Open MMDB database - https://github.com/adulau/mmdb-server"
},
"build_db": "2022-02-06 10:30:25",
"db_source": "GeoOpen-Country-ASN",
"nb_nodes": 1159815
},
"ip": "2a02:21d0::68:69:25",
"country_info": {
"Country": "Belgium",
"Alpha-2 code": "BE",
"Alpha-3 code": "BEL",
"Numeric code": "56",
"Latitude (average)": "50.8333",
"Longitude (average)": "4"
}
}
]
```
# 输出格式
输出格式是一个 JSON 对象数组(以支持提供多个地理位置数据库的能力)。JSON 数组中的每个 JSON 对象都包含 `meta`、`country`、`ip` 和 `country_info` 字段。`country` 给出所查询 IP 地址的地理位置。`meta` 字段包含 MMDB 数据库的来源及其元数据。`ip` 返回查询的 IP 地址。`country_info` 给出关于国家的附加信息,例如 `Country`(国家名称)、`Alpha-2 code`(两位字母代码)、`Alpha-3 code`(三位字母代码)、`Numeric code`(数字代码)、纬度和经度(平均中心值)。
# mmdb-server 公共在线版本
- [https://ip.circl.lu/](https://ip.circl.lu/) - 通过 [https://ip.circl.lu/geolookup/8.8.8.8](https://ip.circl.lu/geolookup/8.8.8.8) 查询
- [https://ipv4.circl.lu](https://ipv4.circl.lu/) 如果您是 IPv6/IPv4 双栈,返回您的 IPv4 地址。
- [https://ipv6.circl.lu](https://ipv6.circl.lu/) 如果您是 IPv6/IPv4 双栈,返回您的 IPv6 地址。
## 如果您只想要源原始 IP 而不需要任何地理查询详细信息
- [https://ip.circl.lu/raw](https://ip.circl.lu/raw)
# 许可证
```
Copyright (C) 2022-2025 Alexandre Dulaunoy
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
```
标签:API服务器, ASN查询, certspotter, Docker, ESC4, _ipv4_, _ipv6_, IP地理定位, MaxMind, MMDB, OSINT, Python, 地理位置, 威胁情报, 安全防御评估, 开发者工具, 快速查询, 情报分析, 数据查询, 无后门, 网络安全, 网络诊断, 请求拦截, 逆向工具, 隐私保护