Skip to content

Instantly share code, notes, and snippets.

@Disasm
Created July 1, 2019 21:54
Show Gist options
  • Save Disasm/dc44684b1f2aa76cd5fbd25ffeea7332 to your computer and use it in GitHub Desktop.
Save Disasm/dc44684b1f2aa76cd5fbd25ffeea7332 to your computer and use it in GitHub Desktop.
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