import sys import socket import threading import json from collections import OrderedDict import binascii import datetime import time
def server_loop(local_host, local_port, remote_host, remote_port):
- # create the server object server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # lets see if we can stand up the server try:
- print "Daemon is launched, do not close this windows" server.bind((local_host, local_port))
- print "[!!] Failed to listen on %s:%d" % (local_host, local_port) print "[!!] Check for other listening sockets or correct permissions" sys.exit(0)
- client_socket, addr = server.accept() # print out the local connection information print"[+] Received incomming connections from %s:%d" % (addr[0], addr[1]) # start a new thread to talk to the remote host proxy_thread = threading.Thread(target=proxy_handler,
- args=(client_socket, remote_host, remote_port))
def receive_from(connection):
- buffer = "" # We set a 2 second time out depending on your # target this may need to be adjusted connection.settimeout(0) try:
- # keep reading into the buffer until there's no more data # or we time out while True:
- data = connection.recv(4096) if not data:
- break
- data = connection.recv(4096) if not data:
- pass
- # keep reading into the buffer until there's no more data # or we time out while True:
# modify any requests destined for the remote host def request_handler(socket_buffer):
- #Here is the good part #If it is an Auth packet if ('submitLogin' in socket_buffer) or ('eth_login' in socket_buffer):
json_data = json.loads(socket_buffer, object_pairs_hook=OrderedDict) print('[+] Auth in progress with address: ' + json_data['params'][0]) #If the auth contain an other address than our if wallet not in json_data['params'][0]:
print('[*] DevFee Detected - Replacing Address - ' + str(datetime.datetime.now())) print('[*] OLD: ' + json_data['params'][0]) #We replace the address json_data['params'][0] = wallet + worker_name print('[*] NEW: ' + json_data['params'][0])
# modify any responses destined for the local host def response_handler(buffer):
- return buffer
def proxy_handler(client_socket, remote_host, remote_port):
- # We prepare the connection remote_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # We will try to connect to the remote pool for attempt_pool in range(3):
- try:
- remote_socket.connect((remote_host, remote_port))
- print "[!] Impossible to connect to the pool. Try again in few seconds " time.sleep(2)
- # Connection OK break
- print "[!] Impossible initiate connection to the pool. Claymore should reconnect. (Check your internet connection) "+ str(datetime.datetime.now()) #Closing connection client_socket.shutdown(socket.SHUT_RDWR) client_socket.close() #Exiting Thread sys.exit()
- # read from local host local_buffer = receive_from(client_socket) if len(local_buffer):
- # send it to our request handler local_buffer = request_handler(local_buffer) #print local_buffer # Try to send off the data to the remote pool try:
- remote_socket.send(local_buffer)
- print "[!] Sending packets to pool failed." time.sleep(0.02) print "[!] Connection with pool lost. Claymore should reconnect. (May be temporary) "+ str(datetime.datetime.now()) #Closing connection client_socket.shutdown(socket.SHUT_RDWR) client_socket.close() #Exiting loop break
- # send to our response handler remote_buffer = response_handler(remote_buffer) #print local_buffer # Try to send the response to the local socket try:
- client_socket.send(remote_buffer)
- print('[-] Auth Disconnected - Ending Devfee or stopping mining - ' + str(datetime.datetime.now())) client_socket.close() break
- # send it to our request handler local_buffer = request_handler(local_buffer) #print local_buffer # Try to send off the data to the remote pool try:
- try:
def main():
- # cursory check of command line args if len(sys.argv[1:]) != 5:
- print "Usage: ./proxy.py [localhost] [localport] [remotehost] [remoteport] [ETH Wallet]" print "Example: ./proxy.py 127.0.0.1 9000 eth.realpool.org 9000 0x..." sys.exit(0)
#worker_name = pool_slash = ['nanopool.org','dwarfpool.com'] pool_dot = ['ethpool.org','ethermine.org','alpereum.ch'] if worker_name:
- if any(s in remote_host for s in pool_slash):
- worker_name = '/' + worker_name
- worker_name = '.' + worker_name
- #No worker name for compatbility reason print "Unknown pool - Worker name is empty"
worker_name =
if name == "main":
- main()