Created
July 1, 2019 21:54
-
-
Save Disasm/dc44684b1f2aa76cd5fbd25ffeea7332 to your computer and use it in GitHub Desktop.
gpg_scan.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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