Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #!/usr/bin/python
  2. import sys
  3. import time
  4. import transmissionrpc
  5. import os.path
  6.  
  7. USER = 'admin'
  8. PASS = 'foobar'
  9. PORT = 9091
  10. HOST = 'localhost'
  11. SLEEP_SECONDS = 20
  12.  
  13. if __name__ == '__main__':
  14.  
  15. if len(sys.argv) != 2:
  16. sys.stderr.write('usage: <logfile>\n')
  17. sys.exit(1)
  18.  
  19. log_file = sys.argv[1]
  20.  
  21. tc = transmissionrpc.Client(HOST, PORT, USER, PASS)
  22. client_set = set()
  23.  
  24. if os.path.isfile(log_file):
  25. f = open(log_file)
  26. for line in f:
  27. slash24 = line.strip()
  28. client_set.add(slash24)
  29. f.close()
  30.  
  31. f = open(log_file, 'a')
  32.  
  33. while 1:
  34. try:
  35. torrent_list = tc.get_torrents()
  36. for torrent in torrent_list:
  37. for peer in torrent.peers:
  38. ipAddress = peer['address']
  39. slash24 = ipAddress[:ipAddress.rfind('.')]+'.0'
  40.  
  41. if slash24 not in client_set:
  42. client_set.add(slash24)
  43. print('logged %s' % slash24)
  44. f.write('%s\n' % slash24)
  45.  
  46. f.flush() #write out all new clients
  47. time.sleep(SLEEP_SECONDS)
  48. except KeyboardInterrupt:
  49. break
  50.  
  51. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement