Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/python
  2.  
  3. import os, re
  4.  
  5. def finddirs():
  6.     r = re.compile("^ssh-[0-9A-z]+$")
  7.     return [ ("/tmp/"+p) for p in os.listdir("/tmp") if r.match(p) ]
  8.  
  9. def dir2path(dir):
  10.     r = re.compile("^agent.[0-9]+$")
  11.     return [ (dir+"/"+f) for f in os.listdir(dir) if r.match(f) ][0]
  12.  
  13. def keyread(path):
  14.     os.environ["SSH_AUTH_SOCK"] = path
  15.     std = os.popen("ssh-add -l 2> /dev/null")
  16.     raw = std.read() # socket is available
  17.     std.close()
  18.     print path, [raw]
  19.     return
  20.  
  21. def main():
  22.     dirs  = finddirs()
  23.     # print dirs
  24.     paths = [ dir2path(dir) for dir in dirs ]
  25.     # print paths
  26.     [ keyread(path) for path in paths ]
  27.     return
  28.  
  29. if __name__ == "__main__": main()
  30.  
  31. # will generate
  32. """
  33. /tmp/ssh-rkxTkt5126/agent.5126 ['The agent has no identities.\n']
  34. /tmp/ssh-XWZBL24682/agent.24682 ['2048 * hoge_rsa (RSA)\n']
  35. /tmp/ssh-CEOck24254/agent.24254 ['2048 * fuga_rsa (RSA)\n']
  36. /tmp/ssh-Hioqcny495/agent.495 ['The agent has no identities.\n']
  37. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement