pickynode 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pickynode +47 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9ed335fbc05dfe5122819dab044c3f087f6855d
|
4
|
+
data.tar.gz: ae580a59583a6c5b355883ee71e76cf8b30f8665
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1051e7d02b39ee86c2a2cc031d484c5f00ac9ee21c9634822395a10ff03702560ff9d5c76d24a4e8fad5374594920b8b42969dfca2159b5161a28c22a86be952
|
7
|
+
data.tar.gz: 7d215790b39f5b36b0f05cb0e4f4e47bdaaa552e4b975d81a6452e558740f0bdf84cf3818879be03fdc44b2366a3e0e8709df101f1a7faf48161e122f1281ec8
|
data/bin/pickynode
CHANGED
@@ -6,15 +6,16 @@ require 'pp'
|
|
6
6
|
require 'trollop'
|
7
7
|
require 'uri'
|
8
8
|
|
9
|
-
VERSION = "0.0.
|
9
|
+
VERSION = "0.0.3"
|
10
10
|
|
11
11
|
opts = Trollop::options do
|
12
12
|
version "pickynode v#{VERSION}"
|
13
|
-
opt :add, "
|
14
|
-
opt :
|
13
|
+
opt :add, "Add node type", :type => :string
|
14
|
+
opt :connect, "Connect to node type", :type => :string
|
15
|
+
opt :ban, "Ban node type", :type => :string
|
15
16
|
opt :debug, "Debug mode"
|
16
17
|
opt :output, "Output commands"
|
17
|
-
opt :disconnect, "
|
18
|
+
opt :disconnect, "Disconnect from node type", :type => :string
|
18
19
|
end
|
19
20
|
|
20
21
|
def run(cmd, opts={})
|
@@ -22,36 +23,58 @@ def run(cmd, opts={})
|
|
22
23
|
`#{cmd}` unless opts[:debug]
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
+
def get_addr_types
|
27
|
+
nodes = `bitcoin-cli getpeerinfo`
|
28
|
+
parsed_nodes = JSON.parse(nodes)
|
29
|
+
parsed_nodes.map { |n| [n["addr"], n["subver"]] }.to_h
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_bitnode_addr_types
|
26
33
|
u = URI.parse("https://bitnodes.21.co/api/v1/snapshots/latest/")
|
27
34
|
nodelist = Net::HTTP.get(u)
|
28
35
|
parsed_nodelist = JSON.parse(nodelist)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
parsed_nodelist['nodes'].map { |k,v| [k, v[1]] }.to_h
|
37
|
+
end
|
38
|
+
|
39
|
+
if opts[:add] || opts[:connect]
|
40
|
+
bitnode_addr_types = get_bitnode_addr_types
|
41
|
+
|
42
|
+
if filter = opts[:add]
|
43
|
+
bitnode_addr_types.each do |k,v|
|
44
|
+
if v.include?(filter)
|
45
|
+
u = URI.parse("https://#{k}")
|
46
|
+
run(%^bitcoin-cli addnode "#{u.host}" "add"^, opts)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if filter = opts[:connect]
|
52
|
+
bitnode_addr_types.each do |k,v|
|
53
|
+
if v.include?(filter)
|
54
|
+
u = URI.parse("https://#{k}")
|
55
|
+
run(%^bitcoin-cli addnode "#{u.host}" "onetry"^, opts)
|
56
|
+
end
|
34
57
|
end
|
35
58
|
end
|
36
59
|
end
|
37
60
|
|
38
|
-
|
39
|
-
|
40
|
-
addr_types = parsed_nodes.map { |n| [n["addr"], n["subver"]] }.to_h
|
61
|
+
if opts[:ban] || opts[:disconnect]
|
62
|
+
addr_types = get_addr_types
|
41
63
|
|
42
|
-
if filter = opts[:
|
43
|
-
|
44
|
-
|
45
|
-
|
64
|
+
if filter = opts[:ban]
|
65
|
+
addr_types.each do |k,v|
|
66
|
+
if v.include?(filter)
|
67
|
+
u = URI.parse("https://#{k}")
|
68
|
+
run(%^bitcoin-cli setban "#{u.host}" "add"^, opts)
|
69
|
+
end
|
46
70
|
end
|
47
71
|
end
|
48
|
-
end
|
49
72
|
|
50
|
-
if filter = opts[:
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
73
|
+
if filter = opts[:disconnect]
|
74
|
+
addr_types.each do |k,v|
|
75
|
+
if v.include?(filter)
|
76
|
+
run(%^bitcoin-cli disconnectnode "#{k}"^, opts)
|
77
|
+
end
|
55
78
|
end
|
56
79
|
end
|
57
80
|
end
|
@@ -60,4 +83,4 @@ unless opts.values.select { |v| v }.empty?
|
|
60
83
|
exit(0)
|
61
84
|
end
|
62
85
|
|
63
|
-
ap
|
86
|
+
ap get_addr_types
|