pickynode 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/pickynode +63 -0
  3. metadata +73 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6b9d5b595e57299acafa3669c2f0dcfef8f582d
4
+ data.tar.gz: 3a72572d6fb73650379a66a0e0228e4b239658da
5
+ SHA512:
6
+ metadata.gz: 1f3c7148c19531e7dd62d81479b474795bfffbc4c532991601500d4aab077d9cf5f3c7684c364702bf98d3ac2886a13c5638108ef170c5acca54c03fc679a5ff
7
+ data.tar.gz: 80eaa361684c68adc403a102e4337385f8c92d29bbbb95eac9b201fce1b4cc3b2a107b1bff74bbc1d82cfb439397fbe203a55902c1abe1073e39dc5a55b5241f
data/bin/pickynode ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ require 'awesome_print'
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'pp'
6
+ require 'trollop'
7
+ require 'uri'
8
+
9
+ VERSION = "0.0.1"
10
+
11
+ opts = Trollop::options do
12
+ version "pickynode v#{VERSION}"
13
+ opt :add, "Node type to add", :type => :string
14
+ opt :ban, "Node type to ban", :type => :string
15
+ opt :debug, "Debug mode"
16
+ opt :output, "Output commands"
17
+ opt :disconnect, "Node type to disconnect", :type => :string
18
+ end
19
+
20
+ def run(cmd, opts={})
21
+ puts "Running #{cmd}" if opts[:output] || opts[:debug]
22
+ `#{cmd}` unless opts[:debug]
23
+ end
24
+
25
+ if filter = opts[:add]
26
+ u = URI.parse("https://bitnodes.21.co/api/v1/snapshots/latest/")
27
+ nodelist = Net::HTTP.get(u)
28
+ parsed_nodelist = JSON.parse(nodelist)
29
+ bitnode_addr_types = parsed_nodelist['nodes'].map { |k,v| [k, v[1]] }.to_h
30
+ bitnode_addr_types.each do |k,v|
31
+ if v.include?(filter)
32
+ u = URI.parse("https://#{k}")
33
+ run(%^bitcoin-cli addnode "#{u.host}" "add"^, opts)
34
+ end
35
+ end
36
+ end
37
+
38
+ nodes = `bitcoin-cli getpeerinfo`
39
+ parsed_nodes = JSON.parse(nodes)
40
+ addr_types = parsed_nodes.map { |n| [n["addr"], n["subver"]] }.to_h
41
+
42
+ if filter = opts[:disconnect]
43
+ addr_types.each do |k,v|
44
+ if v.include?(filter)
45
+ run(%^bitcoin-cli disconnectnode "#{k}"^, opts)
46
+ end
47
+ end
48
+ end
49
+
50
+ if filter = opts[:ban]
51
+ addr_types.each do |k,v|
52
+ if v.include?(filter)
53
+ u = URI.parse("https://#{k}")
54
+ run(%^bitcoin-cli setban "#{u.host}" "add"^, opts)
55
+ end
56
+ end
57
+ end
58
+
59
+ unless opts.values.select { |v| v }.empty?
60
+ exit(0)
61
+ end
62
+
63
+ ap addr_types
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pickynode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josh Ellithorpe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awesome_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: trollop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ description: Some people are picky about the bitcoin nodes they connect to.
42
+ email: quest@mac.com
43
+ executables:
44
+ - pickynode
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - bin/pickynode
49
+ homepage: http://rubygems.org/gems/pickynode
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.6.11
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Manage connections to your bitcoin node
73
+ test_files: []