Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

how to parse msg_version #290

Open
st3b1t opened this issue May 31, 2023 · 0 comments
Open

how to parse msg_version #290

st3b1t opened this issue May 31, 2023 · 0 comments

Comments

@st3b1t
Copy link

st3b1t commented May 31, 2023

my code is it I want parse the text inside messagge version in response from another node:

How can I parse the binary result inside ver_ret and return a structured msg_version object?

#!/usr/bin/env python3

import os, sys, socket
import socket, time, bitcoin
from bitcoin.messages import msg_version
from bitcoin.net import CAddress

serverhost = sys.argv[1]
server_ip = socket.gethostbyname_ex(serverhost)[2][0]
#remote node ip
clienthost = os.uname()[1]
client_ip = socket.gethostbyname_ex(clienthost)[2][1]
#myip

PORT = 8333
bitcoin.SelectParams('mainnet')

def version_pkt(client_ip, server_ip):
    msg = msg_version()
    msg.nVersion = 70002
    msg.addrTo.ip = server_ip
    msg.addrTo.port = PORT
    msg.addrFrom.ip = client_ip
    msg.addrFrom.port = PORT
    return msg

s = socket.socket()

s.connect( (server_ip, PORT) )

s.send( version_pkt(client_ip, server_ip).to_bytes() )

ver_ret = s.recv(1924)

print(ver_ret)

#????

s.close()
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant