Linux tsuru-no-tsurugi 5.15.0-186-generic #196-Ubuntu SMP Sat Jun 20 16:09:34 UTC 2026 x86_64
Apache/2.4.52 (Ubuntu)
Server IP : 192.168.0.18 & Your IP : 216.73.217.105
Domains :
Cant Read [ /etc/named.conf ]
User : www-data
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
usr /
share /
nmap /
nselib /
Delete
Unzip
Name
Size
Permission
Date
Action
data
[ DIR ]
drwxr-xr-x
2024-08-29 14:21
afp.lua
71.48
KB
-rw-r--r--
2023-01-13 02:40
ajp.lua
16.77
KB
-rw-r--r--
2023-01-13 02:40
amqp.lua
10.41
KB
-rw-r--r--
2023-01-13 02:40
anyconnect.lua
4.31
KB
-rw-r--r--
2023-01-13 02:40
asn1.lua
14.57
KB
-rw-r--r--
2023-01-13 02:40
base32.lua
7.36
KB
-rw-r--r--
2023-01-13 02:40
base64.lua
5.83
KB
-rw-r--r--
2023-01-13 02:40
bin.lua
12.99
KB
-rw-r--r--
2023-01-13 02:40
bitcoin.lua
18.25
KB
-rw-r--r--
2023-01-13 02:40
bits.lua
2.54
KB
-rw-r--r--
2023-01-13 02:40
bittorrent.lua
35.76
KB
-rw-r--r--
2023-01-13 02:40
bjnp.lua
9.55
KB
-rw-r--r--
2023-01-13 02:40
brute.lua
50.64
KB
-rw-r--r--
2023-01-13 02:40
cassandra.lua
5.48
KB
-rw-r--r--
2023-01-13 02:40
citrixxml.lua
16
KB
-rw-r--r--
2023-01-13 02:40
coap.lua
75.1
KB
-rw-r--r--
2023-01-13 02:40
comm.lua
11.03
KB
-rw-r--r--
2023-01-13 02:40
creds.lua
18.26
KB
-rw-r--r--
2023-01-13 02:40
cvs.lua
3.05
KB
-rw-r--r--
2023-01-13 02:40
datafiles.lua
11.05
KB
-rw-r--r--
2023-01-13 02:40
datetime.lua
7.5
KB
-rw-r--r--
2023-01-13 02:40
dhcp.lua
28.57
KB
-rw-r--r--
2023-01-13 02:40
dhcp6.lua
19.86
KB
-rw-r--r--
2023-01-13 02:40
dns.lua
51.07
KB
-rw-r--r--
2023-01-13 02:40
dnsbl.lua
19.01
KB
-rw-r--r--
2023-01-13 02:40
dnssd.lua
12.61
KB
-rw-r--r--
2023-01-13 02:40
drda.lua
24.08
KB
-rw-r--r--
2023-01-13 02:40
eap.lua
7.54
KB
-rw-r--r--
2023-01-13 02:40
eigrp.lua
12.98
KB
-rw-r--r--
2023-01-13 02:40
formulas.lua
5.68
KB
-rw-r--r--
2023-01-13 02:40
ftp.lua
9.03
KB
-rw-r--r--
2023-01-13 02:40
geoip.lua
1.71
KB
-rw-r--r--
2023-01-13 02:40
giop.lua
18.42
KB
-rw-r--r--
2023-01-13 02:40
gps.lua
3.38
KB
-rw-r--r--
2023-01-13 02:40
http.lua
117.07
KB
-rw-r--r--
2023-01-13 02:40
httpspider.lua
36.65
KB
-rw-r--r--
2023-01-13 02:40
iax2.lua
9.58
KB
-rw-r--r--
2023-01-13 02:40
idna.lua
17.14
KB
-rw-r--r--
2023-01-13 02:40
ike.lua
14.63
KB
-rw-r--r--
2023-01-13 02:40
imap.lua
9.59
KB
-rw-r--r--
2023-01-13 02:40
informix.lua
39.93
KB
-rw-r--r--
2023-01-13 02:40
ipOps.lua
29.06
KB
-rw-r--r--
2023-01-13 02:40
ipmi.lua
8.08
KB
-rw-r--r--
2023-01-13 02:40
ipp.lua
12.57
KB
-rw-r--r--
2023-01-13 02:40
irc.lua
757
B
-rw-r--r--
2023-01-13 02:40
iscsi.lua
21.38
KB
-rw-r--r--
2023-01-13 02:40
isns.lua
14.98
KB
-rw-r--r--
2023-01-13 02:40
jdwp.lua
43.52
KB
-rw-r--r--
2023-01-13 02:40
json.lua
11.62
KB
-rw-r--r--
2023-01-13 02:40
knx.lua
2.42
KB
-rw-r--r--
2023-01-13 02:40
ldap.lua
31.94
KB
-rw-r--r--
2023-01-13 02:40
lfs.luadoc
1.68
KB
-rw-r--r--
2023-01-13 02:40
libssh2-utility.lua
4.69
KB
-rw-r--r--
2023-01-13 02:40
libssh2.luadoc
4.75
KB
-rw-r--r--
2023-01-13 02:40
listop.lua
4.66
KB
-rw-r--r--
2023-01-13 02:40
lpeg-utility.lua
5.64
KB
-rw-r--r--
2023-01-13 02:40
lpeg.luadoc
351
B
-rw-r--r--
2023-01-13 02:40
ls.lua
10.96
KB
-rw-r--r--
2023-01-13 02:40
match.lua
2.05
KB
-rw-r--r--
2023-01-13 02:40
membase.lua
9.93
KB
-rw-r--r--
2023-01-13 02:40
mobileme.lua
8.46
KB
-rw-r--r--
2023-01-13 02:40
mongodb.lua
21.3
KB
-rw-r--r--
2023-01-13 02:40
mqtt.lua
28.86
KB
-rw-r--r--
2023-01-13 02:40
msrpc.lua
190.07
KB
-rw-r--r--
2023-01-13 02:40
msrpcperformance.lua
29.65
KB
-rw-r--r--
2023-01-13 02:40
msrpctypes.lua
168.52
KB
-rw-r--r--
2023-01-13 02:40
mssql.lua
109.43
KB
-rw-r--r--
2023-01-13 02:40
multicast.lua
5.97
KB
-rw-r--r--
2023-01-13 02:40
mysql.lua
16.03
KB
-rw-r--r--
2023-01-13 02:40
natpmp.lua
5.11
KB
-rw-r--r--
2023-01-13 02:40
nbd.lua
16.04
KB
-rw-r--r--
2023-01-13 02:40
ncp.lua
35.64
KB
-rw-r--r--
2023-01-13 02:40
ndmp.lua
11.43
KB
-rw-r--r--
2023-01-13 02:40
netbios.lua
14.44
KB
-rw-r--r--
2023-01-13 02:40
nmap.luadoc
40.34
KB
-rw-r--r--
2023-01-13 02:40
nrpc.lua
4.46
KB
-rw-r--r--
2023-01-13 02:40
nsedebug.lua
3.49
KB
-rw-r--r--
2023-01-13 02:40
omp2.lua
4.78
KB
-rw-r--r--
2023-01-13 02:40
oops.lua
3.61
KB
-rw-r--r--
2023-01-13 02:40
openssl.luadoc
7.5
KB
-rw-r--r--
2023-01-13 02:40
ospf.lua
15.29
KB
-rw-r--r--
2023-01-13 02:40
packet.lua
36.18
KB
-rw-r--r--
2023-01-13 02:40
pcre.luadoc
6.79
KB
-rw-r--r--
2023-01-13 02:40
pgsql.lua
20.6
KB
-rw-r--r--
2023-01-13 02:40
pop3.lua
5.74
KB
-rw-r--r--
2023-01-13 02:40
pppoe.lua
29.42
KB
-rw-r--r--
2023-01-13 02:40
proxy.lua
11.37
KB
-rw-r--r--
2023-01-13 02:40
punycode.lua
11.5
KB
-rw-r--r--
2023-01-13 02:40
rand.lua
2.7
KB
-rw-r--r--
2023-01-13 02:40
rdp.lua
14.73
KB
-rw-r--r--
2023-01-13 02:40
re.lua
8.22
KB
-rw-r--r--
2023-01-13 02:40
redis.lua
3.61
KB
-rw-r--r--
2023-01-13 02:40
rmi.lua
47.77
KB
-rw-r--r--
2023-01-13 02:40
rpc.lua
107.64
KB
-rw-r--r--
2023-01-13 02:40
rpcap.lua
11.08
KB
-rw-r--r--
2023-01-13 02:40
rsync.lua
5.22
KB
-rw-r--r--
2023-01-13 02:40
rtsp.lua
8.62
KB
-rw-r--r--
2023-01-13 02:40
sasl.lua
16.51
KB
-rw-r--r--
2023-01-13 02:40
shortport.lua
11.99
KB
-rw-r--r--
2023-01-13 02:40
sip.lua
30.07
KB
-rw-r--r--
2023-01-13 02:40
slaxml.lua
17.9
KB
-rw-r--r--
2023-01-13 02:40
smb.lua
173.22
KB
-rw-r--r--
2023-01-13 02:40
smb2.lua
15.34
KB
-rw-r--r--
2023-01-13 02:40
smbauth.lua
37.33
KB
-rw-r--r--
2023-01-13 02:40
smtp.lua
19.85
KB
-rw-r--r--
2023-01-13 02:40
snmp.lua
16
KB
-rw-r--r--
2023-01-13 02:40
socks.lua
8.25
KB
-rw-r--r--
2023-01-13 02:40
srvloc.lua
10.99
KB
-rw-r--r--
2023-01-13 02:40
ssh1.lua
9.15
KB
-rw-r--r--
2023-01-13 02:40
ssh2.lua
11.73
KB
-rw-r--r--
2023-01-13 02:40
sslcert.lua
33.35
KB
-rw-r--r--
2023-01-13 02:40
sslv2.lua
9.68
KB
-rw-r--r--
2023-01-13 02:40
stdnse.lua
32.64
KB
-rw-r--r--
2023-01-13 02:40
strbuf.lua
4.52
KB
-rw-r--r--
2023-01-13 02:40
strict.lua
2.53
KB
-rw-r--r--
2023-01-13 02:40
stringaux.lua
4.32
KB
-rw-r--r--
2023-01-13 02:40
stun.lua
11.08
KB
-rw-r--r--
2023-01-13 02:40
tab.lua
3.35
KB
-rw-r--r--
2023-01-13 02:40
tableaux.lua
2.06
KB
-rw-r--r--
2023-01-13 02:40
target.lua
3.93
KB
-rw-r--r--
2023-01-13 02:40
tftp.lua
9.41
KB
-rw-r--r--
2023-01-13 02:40
tls.lua
58.05
KB
-rw-r--r--
2023-01-13 02:40
tn3270.lua
46.99
KB
-rw-r--r--
2023-01-13 02:40
tns.lua
64.16
KB
-rw-r--r--
2023-01-13 02:40
unicode.lua
14.23
KB
-rw-r--r--
2023-01-13 02:40
unittest.lua
12.41
KB
-rw-r--r--
2023-01-13 02:40
unpwdb.lua
10.42
KB
-rw-r--r--
2023-01-13 02:40
upnp.lua
11.18
KB
-rw-r--r--
2023-01-13 02:40
url.lua
16.7
KB
-rw-r--r--
2023-01-13 02:40
versant.lua
8.58
KB
-rw-r--r--
2023-01-13 02:40
vnc.lua
25.54
KB
-rw-r--r--
2023-01-13 02:40
vulns.lua
76.45
KB
-rw-r--r--
2023-01-13 02:40
vuzedht.lua
16.21
KB
-rw-r--r--
2023-01-13 02:40
wsdd.lua
11.98
KB
-rw-r--r--
2023-01-13 02:40
xdmcp.lua
12.09
KB
-rw-r--r--
2023-01-13 02:40
xmpp.lua
15.91
KB
-rw-r--r--
2023-01-13 02:40
zlib.luadoc
4.88
KB
-rw-r--r--
2023-01-13 02:40
Save
Rename
--- -- This library implements a minimal subset of the BitCoin protocol -- It currently supports the version handshake and processing Addr responses. -- -- The library contains the following classes: -- -- * NetworkAddress - Contains functionality for encoding and decoding the -- BitCoin network address structure. -- -- * Request - Classs containing BitCoin client requests -- o Version - The client version exchange packet -- -- * Response - Class containing BitCoin server responses -- o Version - The server version exchange packet -- o VerAck - The server version ACK packet -- o Addr - The server address packet -- o Inv - The server inventory packet -- -- * Helper - The primary interface to scripts -- --@author Patrik Karlsson <patrik@cqure.net> --@author Andrew Orr <andrew@andreworr.ca> --@copyright Same as Nmap--See https://nmap.org/book/man-legal.html -- -- Version 0.2 -- -- Created 11/09/2011 - v0.1 - created by Patrik Karlsson <patrik@cqure.net> -- Revised 17/02/2012 - v0.2 - fixed count parsing -- - changed version/verack handling to support -- February 20th 2012 bitcoin protocol switchover local ipOps = require "ipOps" local match = require "match" local nmap = require "nmap" local os = require "os" local stdnse = require "stdnse" local string = require "string" local table = require "table" local openssl = stdnse.silent_require('openssl') _ENV = stdnse.module("bitcoin", stdnse.seeall) -- A class that supports the BitCoin network address structure NetworkAddress = { NODE_NETWORK = 1, -- Creates a new instance of the NetworkAddress class -- @param host table as received by the action method -- @param port table as received by the action method -- @return o instance of NetworkAddress new = function(self, host, port) local o = { host = "table" == type(host) and host.ip or host, port = "table" == type(port) and port.number or port, service = NetworkAddress.NODE_NETWORK, } setmetatable(o, self) self.__index = self return o end, -- Creates a new instance of NetworkAddress based on the data string -- @param data string of bytes -- @return na instance of NetworkAddress fromString = function(data) assert(26 == #data, "Expected 26 bytes of data") local na = NetworkAddress:new() local ipv6_prefix, ipv4_addr na.service, ipv6_prefix, ipv4_addr, na.port = string.unpack("<I8 c12 c4 >I2", data) if ipv6_prefix == "\0\0\0\0\0\0\0\0\0\0\xff\xff" then -- IPv4 na.host = ipOps.str_to_ip(ipv4_addr) else na.host = ipOps.str_to_ip(ipv6_prefix .. ipv4_addr) end return na end, -- Converts the NetworkAddress instance to string -- @return data string containing the NetworkAddress instance __tostring = function(self) local ipv6_addr = ipOps.ip_to_str(self.host) return string.pack("<I8 c16 >I2", self.service, ipv6_addr, self.port ) end } -- The request class container Request = { -- The version request Version = { -- Creates a new instance of the Version request -- @param host table as received by the action method -- @param port table as received by the action method -- @param lhost string containing the source IP -- @param lport number containing the source port -- @return o instance of Version new = function(self, host, port, lhost, lport) local o = { host = host, port = port, lhost= lhost, lport= lport, } setmetatable(o, self) self.__index = self return o end, -- Converts the Version request to a string -- @return data as string __tostring = function(self) local magic = 0xD9B4BEF9 local cmd = "version" local len = 85 -- ver: 0.4.0 local ver = 0x9c40 cmd = cmd .. ('\0'):rep(12 - #cmd) -- NODE_NETWORK = 1 local services = 1 local timestamp = os.time() local ra = NetworkAddress:new(self.host, self.port) local sa = NetworkAddress:new(self.lhost, self.lport) local nodeid = openssl.rand_bytes(8) local useragent = "\0" local lastblock = "\0\0\0\0" -- Construct payload in order to calculate checksum for the header local payload = (string.pack("<I4 I8 I8", ver, services, timestamp) .. tostring(ra) .. tostring(sa) .. nodeid .. useragent .. lastblock) -- Checksum is first 4 bytes of sha256(sha256(payload)) local checksum = openssl.digest("sha256", payload) checksum = openssl.digest("sha256", checksum) -- Construct the header without checksum local header = string.pack("<I4 c12 I4", magic, cmd, len) -- After 2012-02-20, version messages require checksums header = header .. checksum:sub(1,4) return header .. payload end, }, -- The GetAddr request GetAddr = { -- Creates a new instance of the Version request -- @param host table as received by the action method -- @param port table as received by the action method -- @param lhost string containing the source IP -- @param lport number containing the source port -- @return o instance of Version new = function(self, host, port, lhost, lport) local o = { host = host, port = port, lhost= lhost, lport= lport, } setmetatable(o, self) self.__index = self return o end, -- Converts the Version request to a string -- @return data as string __tostring = function(self) local magic = 0xD9B4BEF9 local cmd = "getaddr" local len = 0 local chksum = 0xe2e0f65d cmd = cmd .. ('\0'):rep(12 - #cmd) return string.pack("<I4 c12 I4 I4", magic, cmd, len, chksum) end }, VerAck = { new = function(self) local o = {} setmetatable(o, self) self.__index = self return o end, __tostring = function(self) local cmd = "verack" cmd = cmd .. ('\0'):rep(12 - #cmd) return string.pack("<I4 c12 I4 I4", 0xD9B4BEF9, cmd, 0, 0xe2e0f65d) end, }, -- The pong message is sent in response to a ping message. Pong = { new = function(self) local o = {} setmetatable(o, self) self.__index = self return o end, __tostring = function(self) local magic = 0xD9B4BEF9 local cmd = "pong" local len = 0 local chksum = 0xe2e0f65d cmd = cmd .. ('\0'):rep(12 - #cmd) return string.pack("<I4 c12 I4 I4", magic, cmd, len, chksum) end, } } -- The response class container Response = { Header = { size = 24, new = function(self) local o = { magic = 0, cmd = "", length = 0, checksum = 0, } setmetatable(o, self) self.__index = self return o end, parse = function(data) local header = Response.Header:new() local cmd header.magic, cmd, header.length, header.checksum = string.unpack(">I4 c12 I4 I4", data) header.cmd = string.unpack("z", cmd) return header end, }, Alert = { type = "Alert", -- Creates a new instance of Version based on data string -- @param data string containing the raw response -- @return o instance of Version new = function(self, data) local o = { data = data, } setmetatable(o, self) self.__index = self o:parse() return o end, -- Parses the raw data and builds the Version instance parse = function(self) local pos = Response.Header.size + 1 self.header = Response.Header.parse(self.data) local data pos, data = Util.decodeVarString(self.data, pos) -- -- TODO: Alert decoding goes here -- return end, }, -- The version response message Version = { -- Creates a new instance of Version based on data string -- @param data string containing the raw response -- @return o instance of Version new = function(self, data) local o = { data = data } setmetatable(o, self) self.__index = self o:parse() return o end, -- Parses the raw data and builds the Version instance parse = function(self) local ra, sa, cmd, nodeid, pos -- After 2012-02-20, version messages contain checksums self.magic, cmd, self.len, self.checksum, self.ver_raw, self.service, self.timestamp, ra, sa, nodeid, pos = string.unpack("<I4 c12 I4 I4 I4 I8 I8 c26 c26 c8", self.data) pos, self.user_agent = Util.decodeVarString(self.data, pos) self.lastblock, pos = string.unpack("<I4", self.data, pos) self.nodeid = stdnse.tohex(nodeid) self.cmd = string.unpack("z", cmd) local function decode_bitcoin_version(n) if ( n < 31300 ) then local minor, micro = n // 100, n % 100 return ("0.%d.%d"):format(minor, micro) else local minor, micro = n // 10000, (n // 100) % 100 return ("0.%d.%d"):format(minor, micro) end end self.ver = decode_bitcoin_version(self.ver_raw) self.sa = NetworkAddress.fromString(sa) self.ra = NetworkAddress.fromString(ra) end, }, -- The verack response message VerAck = { -- Creates a new instance of VerAck based on data string -- @param data string containing the raw response -- @return o instance of Version new = function(self, data) local o = { data = data } setmetatable(o, self) self.__index = self o:parse() return o end, -- Parses the raw data and builds the VerAck instance parse = function(self) local cmd -- After 2012-02-20, VerAck messages contain checksums self.magic, cmd, self.checksum = string.unpack("<I4 c12 I4", self.data) self.cmd = string.unpack("z", cmd) end, }, -- The Addr response message Addr = { -- Creates a new instance of VerAck based on data string -- @param data string containing the raw response -- @return o instance of Addr new = function(self, data, version) local o = { data = data, version=version } setmetatable(o, self) self.__index = self o:parse() return o end, -- Parses the raw data and builds the Addr instance parse = function(self) local pos, count local cmd self.magic, cmd, self.len, self.chksum, pos = string.unpack("<I4 c12 I4 I4", self.data) self.cmd = string.unpack("z", cmd) pos, count = Util.decodeVarInt(self.data, pos) self.addresses = {} for c=1, count do if ( self.version > 31402 ) then local timestamp, data timestamp, data, pos = string.unpack("<I4 c26", self.data, pos) local na = NetworkAddress.fromString(data) table.insert(self.addresses, { ts = timestamp, address = na }) end end end, }, -- The inventory server packet Inv = { -- Creates a new instance of Inv based on data string -- @param data string containing the raw response -- @return o instance of Inv new = function(self, data, version) local o = { data = data, version=version } setmetatable(o, self) self.__index = self o:parse() return o end, -- Parses the raw data and builds the Inv instance parse = function(self) local cmd self.magic, cmd, self.len, self.chksum = string.unpack("<I4 c12 I4 I4", self.data) self.cmd = string.unpack("z", cmd) -- TODO parse inv_vect end, }, -- Receives the packet and decodes it -- @param socket socket connected to the server -- @param version number containing the server version -- @return status true on success, false on failure -- @return response instance of response packet if status is true -- err string containing the error message if status is false recvPacket = function(socket, version) local status, header = socket:receive_buf(match.numbytes(24), true) if ( not(status) ) then return false, "Failed to read the packet header" end local magic, cmd, len, checksum = string.unpack("<I4 c12 I4 I4", header) local data = "" cmd = string.unpack("z", cmd) -- the verack and ping has no payload if ( 0 ~= len ) then status, data = socket:receive_buf(match.numbytes(len), true) if ( not(status) ) then return false, "Failed to read the packet header" end else -- The ping message is sent primarily to confirm that the TCP/IP connection is still valid. if( cmd == "ping" ) then local req = Request.Pong:new() local status, err = socket:send(tostring(req)) if ( not(status) ) then return false, "Failed to send \"Pong\" reply to server" else return Response.recvPacket(socket, version) end end end return Response.decode(header .. data, version) end, -- Decodes the raw packet data -- @param data string containing the raw packet -- @param version number containing the server version -- @return status true on success, false on failure -- @return response instance of response packet if status is true -- err string containing the error message if status is false decode = function(data, version) local magic, cmd = string.unpack("<I4 z", data) if ( "version" == cmd ) then return true, Response.Version:new(data) elseif ( "verack" == cmd ) then return true, Response.VerAck:new(data) elseif ( "addr" == cmd ) then return true, Response.Addr:new(data, version) elseif ( "inv" == cmd ) then return true, Response.Inv:new(data) elseif ( "alert" == cmd ) then return true, Response.Alert:new(data) else return true, ("Unknown command (%s)"):format(cmd) end end, } Util = { varIntLen = { [0xfd] = 2, [0xfe] = 4, [0xff] = 8, }, -- Decodes a variable length int -- @param data string of data -- @param pos the location within the string to decode -- @return pos the new position -- @return count number the decoded argument decodeVarInt = function(data, pos) local count, pos = string.unpack("B", data, pos) if count >= 0xfd then count, pos = string.unpack("<I" .. Util.varIntLen[count], data, pos) end return pos, count end, decodeVarString = function(data, pos) local count, pos = string.unpack("B", data, pos) local str if count < 0xfd then str, pos = string.unpack("s1", data, pos - 1) else str, pos = string.unpack("<s" .. Util.varIntLen[count], data, pos) end return pos, str end, } -- The Helper class used as a primary interface to scripts Helper = { -- Creates a new Helper instance -- @param host table as received by the action method -- @param port table as received by the action method -- @param options table containing additional options -- <code>timeout</code> - the socket timeout in ms -- @return instance of Helper new = function(self, host, port, options) local o = { host = host, port = port, options = options or {} } setmetatable(o, self) self.__index = self return o end, -- Connects to the BitCoin Server -- @return status true on success false on failure -- @return err string containing the error message in case status is false connect = function(self) self.socket = nmap.new_socket() self.socket:set_timeout(self.options.timeout or 10000) local status, err = self.socket:connect(self.host, self.port) if ( not(status) ) then return false, err end status, self.lhost, self.lport = self.socket:get_info() return status, (status and nil or self.lhost) end, -- Performs a version handshake with the server -- @return status, true on success false on failure -- @return version instance if status is true -- err string containing an error message if status is false exchVersion = function(self) if ( not(self.socket) ) then return false end local req = Request.Version:new( self.host, self.port, self.lhost, self.lport ) local status, err = self.socket:send(tostring(req)) if ( not(status) ) then return false, "Failed to send \"Version\" request to server" end local version status, version = Response.recvPacket(self.socket) if not status or not version then return false, "Failed to read \"Version\" response from server: " .. (version or "nil") elseif version.cmd ~= "version" then return false, ('"Version" request got %s from server'):format(version.cmd) end if ( version.ver_raw > 29000 ) then local status, verack = Response.recvPacket(self.socket) end local verack = Request.VerAck:new() local status, err = self.socket:send(tostring(verack)) if ( not(status) ) then return false, "Failed to send \"Version\" request to server" end self.version = version.ver_raw return status, version end, getNodes = function(self) local req = Request.GetAddr:new( self.host, self.port, self.lhost, self.lport ) local status, err = self.socket:send(tostring(req)) if ( not(status) ) then return false, "Failed to send \"GetAddr\" request to server" end local status, response = Response.recvPacket(self.socket, self.version) local all_addrs = {} local limit = 10 -- Usually sends an addr response with 1 address, -- then some other stuff like getheaders or ping, -- then one with hundreds of addrs. while status and #all_addrs <= 1 and limit > 0 do limit = limit - 1 status, response = Response.recvPacket(self.socket, self.version) if status and response.cmd == "addr" then for _, addr in ipairs(response.addresses) do all_addrs[#all_addrs+1] = addr end end end return #all_addrs > 0, all_addrs end, -- Reads a message from the server -- @return status true on success, false on failure -- @return response instance of response packet if status is true -- err string containing the error message if status is false readMessage = function(self) assert(self.version, "Version handshake has not been performed") return Response.recvPacket(self.socket, self.version) end, -- Closes the connection to the server -- @return status true on success false on failure -- @return err code, if status is false close = function(self) return self.socket:close() end } return _ENV;