-
Notifications
You must be signed in to change notification settings - Fork 11
/
tcpclient.py
87 lines (68 loc) · 2.09 KB
/
tcpclient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import socket, struct, os, binascii, base64, subprocess
import telnetlib
import base58 # https://raw.githubusercontent.com/keis/base58/master/base58.py
def readline(sc, show = True):
res = ""
while len(res) == 0 or res[-1] != "\n":
data = sc.recv(1)
if len(data) == 0:
print repr(res)
raise Exception("Server disconnected")
res += data
if show:
print repr(res[:-1])
return res[:-1]
def read_until(sc, s):
res = ""
while not res.endswith(s):
data = sc.recv(1)
if len(data) == 0:
print repr(res)
raise Exception("Server disconnected")
res += data
return res[:-(len(s))]
def read_all(sc, n):
data = ""
while len(data) < n:
block = sc.recv(n - len(data))
if len(block) == 0:
print repr(data)
raise Exception("Server disconnected")
data += block
return data
def I(n):
return struct.pack("<I", n)
def Q(n):
return struct.pack("<Q", n)
def gen_addr(prefix):
for a in '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz':
for b in '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz':
res = base58.b58decode((prefix+a+b).ljust(33, "1"))
res = base58.b58encode_check(res[0:21])
if res.startswith(prefix):
return res
return None
sc = socket.create_connection(("66.172.27.77", 11019))
read_until(sc, "Are you ready? [Y]es or [N]o:")
sc.send("Y\n")
read_until(sc, "Send a BTC valid address that starts with ")
prefix = read_until(sc, ":")
print prefix
res = gen_addr(prefix)
print res
if res == None:
print "No valid BTC addr"
exit()
sc.send(res + "\n")
read_until(sc, "[Q]uit")
sc.send("S\n")
read_until(sc, "send the first string:")
sc.send("\x00" * 504 + "\x00" + "\n")
read_until(sc, "send the second string:")
sc.send("\x00" * 504 + "\x01" + "\n")
while True:
data = sc.recv(16384)
if len(data) == 0:
break
for line in data.split("\n"):
print repr(line)