{"id":23486823,"url":"https://github.com/do1e/ip-api","last_synced_at":"2025-10-05T17:14:28.167Z","repository":{"id":265113532,"uuid":"895182797","full_name":"Do1e/IP-API","owner":"Do1e","description":"一个部署在服务器上的支持跨域的IP查询服务，返回访问者的IP及其地理位置信息。","archived":false,"fork":false,"pushed_at":"2025-01-11T15:15:03.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-03T20:53:24.421Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Do1e.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-27T17:54:43.000Z","updated_at":"2025-01-11T15:15:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"2983e857-9b0f-4b78-a03d-704196392d8a","html_url":"https://github.com/Do1e/IP-API","commit_stats":null,"previous_names":["do1e/ip-api"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Do1e/IP-API","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Do1e%2FIP-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Do1e%2FIP-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Do1e%2FIP-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Do1e%2FIP-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Do1e","download_url":"https://codeload.github.com/Do1e/IP-API/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Do1e%2FIP-API/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278486308,"owners_count":25994945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-24T22:17:23.564Z","updated_at":"2025-10-05T17:14:28.147Z","avatar_url":"https://github.com/Do1e.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IP-API\r\n\r\n一个部署在服务器上的支持跨域的IP查询服务，返回访问者的IP及其地理位置信息。\r\n\r\n\u003cp\u003eIP地址位置数据由\u003ca href=\"https://www.cz88.net\"\u003e纯真CZ88\u003c/a\u003e提供支持\u003c/p\u003e\r\n\r\n## 环境变量\r\n\r\n1. `KEY`: 用于czdb解码的密钥，不配置则关闭解析地理位置信息\r\n2. `DOWNLOAD_KEY`：下载czdb的UUID，指下载链接后面的key参数\r\n3. `UPDATE_TIME`：每天更新czdb的时间，默认为`12:00`，需要注意的是这个时间默认为格林威治标准时间。\r\n4. `SUBURL`：api的子路径，默认为`/`\r\n5. `PORT`：端口，默认为`8000`\r\n6. `DB_PATH`：czdb文件路径，默认为`./data`\r\n\r\n## 使用\r\n\r\n### Docker\r\n\r\n#### 无CZDB启动，仅返回IP\r\n\r\n```bash\r\ndocker run -d --restart=always --name ipapi \\\r\n    -e PORT=5125 \\\r\n    -e SUBURL=/get-ip \\\r\n    --network host \\\r\n    do1e/ip-api:latest\r\n```\r\n\r\n#### 使用CZDB解析地理位置信息\r\n\r\n```bash\r\ndocker run -d --restart=always --name ipapi \\\r\n    -e PORT=5125 \\\r\n    -e SUBURL=/get-ip \\\r\n    -e DOWNLOAD_KEY=abcdefgh-0312-2001-3012-666666666666 \\\r\n    -e KEY=ABCDEFGhijklmnopqrsTUV== \\\r\n    -v ./data:/app/data \\\r\n    --network host \\\r\n    do1e/ip-api:latest\r\n```\r\n\r\n#### nginx反代参考\r\n\r\n```nginx\r\nserver {\r\n    listen 443 ssl;\r\n    listen [::]:443 ssl;\r\n    server_name example.com;\r\n    access_log /var/log/nginx/ipapi.access.log;\r\n    error_log /var/log/nginx/ipapi.error.log;\r\n    location /get-ip {\r\n        proxy_pass http://127.0.0.1:5125;\r\n        proxy_http_version 1.1;\r\n        proxy_set_header Upgrade $http_upgrade;\r\n        proxy_set_header Connection \"upgrade\";\r\n        proxy_set_header Host $host;\r\n        proxy_set_header X-Real-IP $remote_addr;\r\n        proxy_set_header X-Real-PORT $remote_port;\r\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n    }\r\n}\r\n```\r\n\r\n加上`-v /etc/localtime:/etc/localtime:ro`以使用系统时间进行更新。或者`-e TZ=xxx`指定时区，如`-e TZ=Asia/Shanghai`。\r\n\r\n#### 返回示例\r\n\r\nIPv4  \r\n```json\r\n{\r\n  \"ip\": \"114.xxx.xxx.xxx\",\r\n  \"region\": \"中国–江苏–南京 教育网/南京大学\",\r\n  \"error\": null\r\n}\r\n```\r\n\r\nIPv6  \r\n```json\r\n{\r\n  \"ip\": \"2001:xxxx:xxxx:xxxx::xxxx\",\r\n  \"region\": \"中国 教育网\",\r\n  \"error\": null\r\n}\r\n```\r\n\r\n### 本地或Vercel部署\r\n\r\n```bash\r\ngit clone https://github.com/tagphi/czdb_searcher_python.git\r\nmv czdb_searcher_python/czdb .\r\nrm -rf czdb_searcher_python\r\npip install -r requirements.txt\r\n```\r\n\r\n新建`.env`文件如下，填入环境变量，然后运行`python main.py`即可。\r\n\r\n```dotenv\r\nPORT=5125\r\nSUBURL=get-ip\r\nDOWNLOAD_KEY=abcdefgh-0312-2001-3012-666666666666\r\nKEY=ABCDEFGhijklmnopqrsTUV==\r\nDB_PATH=/tmp\r\nUPDATE_TIME=12:00\r\n```\r\n\r\n完成上述配置后，可以使用`vercel`部署。\r\n\r\n```bash\r\nnpm install -g vercel\r\nvercel login\r\nvercel --prod\r\n```\r\n\r\n注：Vercel部署时`DB_PATH`仅能在/tmp目录下\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdo1e%2Fip-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdo1e%2Fip-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdo1e%2Fip-api/lists"}