如何获取GitHub仓库提交代码用户的IP地址?API调用无相关信息
能否获取GitHub仓库中提交代码用户的IP地址?
我尝试调用Commits API,但返回结果中未包含相关信息。
curl --request GET --url "https://api.github.com/repos/org/test-public-repo/commits/b46fffeeac69892470eea14692c218ea7a09ac10" \ --header "Authorization: Bearer $TOKEN" \ --header "X-GitHub-Api-Version: 2022-11-28"
输出结果
{ "sha": "b46fffeeac69892470eea14692c218ea7a09ac10", "node_id": "C_kwDOKRgIVtoAKGI0NmZmZmVlYWM2OTg5MjQ3MGVlYTE0NjkyYzIxOGVhN2EwOWFjMTA", "commit": { "author": { "name": "FName LName", "email": "email@domain.com", "date": "2023-09-09T21:05:38Z" }, "committer": { "name": "FName LName", "email": "email@domain.com", "date": "2023-09-09T21:05:38Z" }, "message": "feat: test ip", "tree": { "sha": "912b9f298c81c371c7da2070bc860964d124cfeb", "url": "https://api.github.com/repos/org/test-public-repo/git/trees/912b9f298c81c371c7da2070bc860964d124cfeb" }, "url": "https://api.github.com/repos/org/test-public-repo/git/commits/b46fffeeac69892470eea14692c218ea7a09ac10", "comment_count": 0, "verification": { "verified": false, "reason": "unsigned", "signature": null, "payload": null } }, "url": "https://api.github.com/repos/org/test-public-repo/commits/b46fffeeac69892470eea14692c218ea7a09ac10", "html_url": "https://github.com/org/test-public-repo/commit/b46fffeeac69892470eea14692c218ea7a09ac10", "comments_url": "https://api.github.com/repos/org/test-public-repo/commits/b46fffeeac69892470eea14692c218ea7a09ac10/comments", "author": { "login": "github-user", "id": 11111, "node_id": "MDQ6VXNlcjcwODIyNzEw", "avatar_url": "https://avatars.githubusercontent.com/u/70822710?v=4", "gravatar_id": "", "url": "https://api.github.com/users/github-user", "html_url": "https://github.com/github-user", "followers_url": "https://api.github.com/users/github-user/followers", "following_url": "https://api.github.com/users/github-user/following{/other_user}", "gists_url": "https://api.github.com/users/github-user/gists{/gist_id}", "starred_url": "https://api.github.com/users/github-user/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/github-user/subscriptions", "organizations_url": "https://api.github.com/users/github-user/orgs", "repos_url": "https://api.github.com/users/github-user/repos", "events_url": "https://api.github.com/users/github-user/events{/privacy}", "received_events_url": "https://api.github.com/users/github-user/received_events", "type": "User", "site_admin": false }, "committer": { "login": "github-user", "id": 11111, "node_id": "MDQ6VXNlcjcwODIyNzEw", "avatar_url": "https://avatars.githubusercontent.com/u/11111?v=4", "gravatar_id": "", "url": "https://api.github.com/users/github-user", "html_url": "https://github.com/github-user", "followers_url": "https://api.github.com/users/github-user/followers", "following_url": "https://api.github.com/users/github-user/following{/other_user}", "gists_url": "https://api.github.com/users/github-user/gists{/gist_id}", "starred_url": "https://api.github.com/users/github-user/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/github-user/subscriptions", "organizations_url": "https://api.github.com/users/github-user/orgs", "repos_url": "https://api.github.com/users/github-user/repos", "events_url": "https://api.github.com/users/github-user/events{/privacy}", "received_events_url": "https://api.github.com/users/github-user/received_events", "type": "User", "site_admin": false }, "parents": [ { "sha": "26c26f8856cd81d9f9144e6654897320f4b9f575", "url": "https://api.github.com/repos/org/test-public-repo/commits/26c26f8856cd81d9f9144e6654897320f4b9f575", "html_url": "https://github.com/org/test-public-repo/commit/26c26f8856cd81d9f9144e6654897320f4b9f575" } ], "stats": { "total": 1, "additions": 1, "deletions": 0 }, "files": [ { "sha": "e389600420ded46e657d418951fa716c9f18bb12", "filename": "README.md", "status": "modified", "additions": 1, "deletions": 0, "changes": 1, "blob_url": "https://github.com/org/test-public-repo/blob/b46fffeeac69892470eea14692c218ea7a09ac10/README.md", "raw_url": "https://github.com/org/test-public-repo/raw/b46fffeeac69892470eea14692c218ea7a09ac10/README.md", "contents_url": "https://api.github.com/repos/org/test-public-repo/contents/README.md?ref=b46fffeeac69892470eea14692c218ea7a09ac10", "patch": "@@ -2,3 +2,4 @@\n test\n \n ii\n+aa" } ] }
解答
GitHub的Commits API确实不会返回提交者的IP地址,这属于用户隐私信息,GitHub不会通过公开API对外暴露。
不过有两种途径可以获取相关IP信息:
- 仓库管理员查看审计日志:组织仓库或私有仓库的管理员,可通过GitHub后台的审计日志查看提交操作对应的IP地址,日志会记录用户执行该操作时的IP。
- 网页端提交的特殊情况:如果提交是直接在GitHub网页上编辑文件完成的,仓库审计日志会包含该提交的IP;但如果是本地Git push的提交,审计日志只会记录push操作的IP,而非提交本身的IP——因为本地Git提交本身不会记录IP,只有推送到GitHub时的IP会被平台记录。
另外需要注意:本地Git提交仅记录用户配置的姓名、邮箱和日期,这些信息和IP没有关联。
内容的提问来源于stack exchange,提问作者DmitrySemenov
相关产品推荐
相关产品推荐

