def main(): if '-gen' in sys.argv: A = int(sys.argv[2]) B = int(sys.argv[3]) ip_block(A, B) # Create a way to run this distributed from python elif '-multi-setup' in sys.argv: import network workers = [] peers = {} # Determine which nodes are available to work for n in network.get_node_names(): name = n.split('/')[-1].split('.')[0] h, i, p, m = utils.load_credentials(name, False) peers[name] = [h, i, p, m] # check if online if network.check_connected(h, i, p): workers.append(name) else: print '%s@%s offline' % (name, i) # Now distribute the assignments print '[*] %d Workers Available' % len(workers) for w in workers: # give them the latest copy of this program H, I, P, M = peers[w] rpath = '/home/%s/Documents/PoolParty/code/0.6/' % H if utils.remote_file_exists(H, I, P, rpath + 'trace.py'): utils.ssh_exec('rm %strace.py' % rpath, I, H, P, False) utils.put_file('trace.py', rpath, H, I, P, False) # Now give them a ip_space.txt file and a script to run trace.py utils.ssh_exec('rm %shops.txt' % rpath, I, H, P, True) # c = 'cd %s; python trace.py 0>&-' % rpath # put this in a .sh script and transfer, then execute # utils.ssh_exec('cd %s; python trace.py 0>&-' % rpath,H,I,P,False) elif '-multi-view' in sys.argv: import tracewatch print('[*] Monitoring Traces...') else: ips = list(utils.swap('ip_space.txt', False)) if not os.path.isfile(os.getcwd() + '/hops.txt'): os.system('touch hops.txt') random.shuffle(ips) pool = multiprocessing.Pool(10) for ip in ips: try: event = pool.apply_async(func=trace, args=(ip, False)) hopdata, nhops = event.get(timeout=60) print ' - %d hops to %s' % (nhops, ip) open('hops.txt', 'a').write('%s:%d\n' % (ip, nhops)) except multiprocessing.TimeoutError: open('hops.txt', 'a').write('%s:?\n' % ip) pass
def load_workers(): nodes = network.get_node_names() workers = [] peers = {} # Determine which nodes are available to work for n in network.get_node_names(): name = n.split('/')[-1].split('.')[0] h, i, p, m = utils.load_credentials(name, False) peers[name] = [h, i, p, m] # check if online rp = '/home/%s/Documents/PoolParty/code/0.6/hops.txt' % h if network.check_connected(h, i, p) and utils.remote_file_exists( h, i, p, rp): workers.append(name) else: print '%s@%s offline' % (name, i) # Now distribute the assignments print '[*] %d Machines Actively Working' % len(workers) return workers, peers
def check_disconnected_nodes(self, threadpool, verbose): for node in network.get_node_names(): if node not in self.workers.keys(): # see if node is now connected h, i, p, m = utils.load_credentials(node, False) e = threadpool.apply_async(func=network.check_connected, args=( h, i, p, )) try: self.workers[node]['connected'] = e.get(timeout=5) except multiprocessing.context.TimeoutError: self.disconnect_node_from_pool(node) pass except IndexError: self.disconnect_node_from_pool(node) pass if self.workers[node]['connected']: self.connect_node_to_pool(node) elif not self.workers[node]['connected']: # see if node is now connected h = self.workers[node]['hname'] i = self.workers[node]['ip'] p = self.workers[node]['pword'] m = self.workers[node]['mac'] print('[!!] checking if %s [%s] might have a new ip...' % (h, m)) e = threadpool.apply_async(func=network.check_connected, args=( h, i, p, )) try: self.workers[node]['connected'] = e.get(timeout=5) except multiprocessing.context.TimeoutError: self.disconnect_node_from_pool(node) pass except IndexError: self.disconnect_node_from_pool(node) pass if self.workers[node]['connected']: self.connect_node_to_pool(node) else: # check if mac matches another ip in LAN updated_client_table = network.find_missing_nodes()
def test_connections(debug): n_threads = 10 peers = {} pool = multiprocessing.Pool(n_threads) # Load Peer Credentials peer_list = network.get_node_names() random.shuffle(peer_list) for node in peer_list: n = node.split('/')[-1].split('.')[0] host, host_ip, host_pass, host_mac = utils.load_credentials(n, debug) # test_cnx = utils.ssh_exec('whoami', host_ip, host, host_pass, False).pop() event = pool.apply_async(func=utils.ssh_exec, args=( 'whoami', host_ip, host, host_pass, False, )) try: test_cnx = event.get(timeout=10).pop() except multiprocessing.context.TimeoutError: test_cnx = '' pass except IndexError: test_cnx = '' pass peer = { 'hname': host, 'ip': host_ip, 'pword': host_pass, 'mac': host_mac, 'connected': False } if test_cnx.replace('\n', '') == host: print('[*] Connected to %s' % node) peer['connected'] = True else: print('[!] Unable to connect to %s' % node) # TODO: Search for that MAC address on the network! peers[node] = peer return peers