Post
Topic
Board Bitcoin Discussion
Merits 1 from 1 user
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
albert0bsd
on 21/07/2024, 18:48:33 UTC
⭐ Merited by nomachine (1)
Here is the script.

Nice script i really like it, i may learn something from you Smiley

Here there is a function that I use for my keyhunt bsgsd server:

Code:
def send_and_receive_line(host, port, message):
    # Create a TCP socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try:
        # Connect to the server
        sock.connect((host, port))

        # Send the message
        start_time = time.time()
        sock.sendall(message.encode())

        # Receive the reply
        reply = sock.recv(1024).decode()
        end_time = time.time()

        # Calculate the elapsed time
        elapsed_time = end_time - start_time
        sock.close()
        return reply, elapsed_time
    except ConnectionResetError:
        print("Server closed the connection without replying.")
        return None, None
    except ConnectionRefusedError:
        print("Connection refused. Make sure the server is running and the host/port are correct.")
        return None, None
    except AttributeError:
        return None, None

This function only send a message to a IP:port and wait for the reply returning it also the time elapsed (For speed calculation)

I call the previous function with this one that format the publickey with range_A:range_B

Code:
def keyhunt_client(target):
    host = 'localhost'  # Change this to the server's hostname or IP address
    port = 8080       # Change this to the server's port number
    message = "{} {}:{}".format(target["publickey"],target["start"],target["end"])
    reply, elapsed_time = send_and_receive_line(host, port, message)
    if( reply != "404 Not Found"):
        return reply
    else:
        return None

I use some target because i have a list of all puzzles with their respective ranks

With those codes you don't depend of Netcat  or shell commands.