Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
gpg_scan.py
#!/usr/bin/env python3
import os
import subprocess
import re
def main():
pubring = os.path.join(os.getenv("HOME", "~"), ".gnupg", "pubring.gpg")
output = subprocess.check_output(["gpg", "--list-packets", pubring])
output = output.decode("utf8")
items = output.split("\n#")
current_keyid = "??"
counts = {}
for item in items:
if ":public key packet:" in item:
m = re.search(r'keyid: ([0-9a-fA-F]+)', item)
current_keyid = m.group(1)
if ":signature packet:" in item:
counts[current_keyid] = counts.get(current_keyid, 0) + 1
for key in counts.keys():
print(key, counts[key])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.