Advertisement
pantteri

Simple botmaster for distributed calculating

Sep 9th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # This program is used to distribute tasks on a botnet.
  5. # Basically, this program is just an UDP server, that counts
  6. # integers. Each bot gets a unique integer.
  7. #
  8. # Code by Felix
  9.  
  10. import socket
  11. import sys
  12.  
  13. if __name__ == '__main__':
  14.    
  15.     # Usage
  16.     if len(sys.argv) < 2:
  17.         print 'Usage: python scheduler.py <max_id> [<port>]'
  18.         exit(255)
  19.    
  20.     # Maximum and current value for unique integers
  21.     max = int(sys.argv[1])
  22.     counter = 0
  23.    
  24.     # Specified port?
  25.     port = 0
  26.     if len(sys.argv) >= 3:
  27.         port = int(sys.argv[2])
  28.  
  29.     # Initialize socket
  30.     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  31.     s.bind(('', port))
  32.     port = s.getsockname()[1]
  33.     print 'Server running on port %i' % port
  34.  
  35.     # Give jobs
  36.     while counter < max:
  37.  
  38.         data, addr = s.recvfrom(1024)
  39.         if data.strip('\n') == 'I am your slave.': # secret code
  40.             s.sendto(str(counter), addr)
  41.             print '\r' + str(counter),
  42.             counter += 1
  43.  
  44.     print 'Done'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement