Skip to content

Instantly share code, notes, and snippets.

@alfonsrv
Created November 26, 2022 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfonsrv/965f0dd598a0a8b60db8e50e796384a7 to your computer and use it in GitHub Desktop.
Save alfonsrv/965f0dd598a0a8b60db8e50e796384a7 to your computer and use it in GitHub Desktop.
Find GitHub users' email addresses by their commit mails – quick and dirty scanner; yikes!
import requests
from collections import Counter
# Create empty token to authenticate against GitHub API (no checkboxes checked)
TOKEN = ''
# Define the user you'd like to scan mails for
USER = ''
BASE_URL = 'https://api.github.com'
PARAMS = {
'per_page': 100
}
NO_REPLY = False # ignore Github no-reply mail addresses
SEARCH_FOR_MAIL = ''
def search_mail(commits: list):
if not SEARCH_FOR_MAIL: return
for commit in commits:
if commit['commit']['author']['email'] == SEARCH_FOR_MAIL:
print(commit['html_url'])
if __name__ == '__main__':
s = requests.Session()
s.headers = {
'Accept': 'application/vnd.github+json',
'Authorization': f'Bearer {TOKEN}',
'User-Agent': 'alfonsrv scanner'
}
response = s.get(f'{BASE_URL}/users/{USER}/repos', params=PARAMS)
repos = [r['name'] for r in response.json()]
commits = []
for repo in repos:
response = s.get(f'{BASE_URL}/repos/{USER}/{repo}/commits', params=PARAMS)
commits.extend(response.json())
no_reply_address = lambda m: ('users.noreply.github.com' in m and not NO_REPLY)
mails = [
(c['commit']['author']['name'], c['commit']['author']['email'])
for c in commits
if isinstance(c, dict)
and not no_reply_address(c['commit']['author']['email'])
]
search_mail(commits)
print(mails)
print(' ')
print(Counter(mails))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment