Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- import time
- import transmissionrpc
- import os.path
- USER = 'admin'
- PASS = 'foobar'
- PORT = 9091
- HOST = 'localhost'
- SLEEP_SECONDS = 20
- if __name__ == '__main__':
- if len(sys.argv) != 2:
- sys.stderr.write('usage: <logfile>\n')
- sys.exit(1)
- log_file = sys.argv[1]
- tc = transmissionrpc.Client(HOST, PORT, USER, PASS)
- client_set = set()
- if os.path.isfile(log_file):
- f = open(log_file)
- for line in f:
- slash24 = line.strip()
- client_set.add(slash24)
- f.close()
- f = open(log_file, 'a')
- while 1:
- try:
- torrent_list = tc.get_torrents()
- for torrent in torrent_list:
- for peer in torrent.peers:
- ipAddress = peer['address']
- slash24 = ipAddress[:ipAddress.rfind('.')]+'.0'
- if slash24 not in client_set:
- client_set.add(slash24)
- print('logged %s' % slash24)
- f.write('%s\n' % slash24)
- f.flush() #write out all new clients
- time.sleep(SLEEP_SECONDS)
- except KeyboardInterrupt:
- break
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement