how to parse msg_version
Opened this issue · 0 comments
st3b1t commented
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()