emonti-rbkb 0.6.1.3 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/hexify CHANGED
@@ -1,85 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # Author Eric Monti (emonti at matasano)
3
- #
4
- # hexify converts a string or raw data to hex characters. Input can be
5
- # supplied via stdin, a string argument, or a file (with -f).
6
- #
7
- # Usage: hexify [options] <data | blank for stdin>
8
- # -h, --help Show this message
9
- # -v, --version Show version and exit
10
- # -f, --file FILENAME Input from FILENAME
11
- # -l, --length LEN Hexify in lines of LEN bytes
12
- # -d, --delim=DELIMITER DELIMITER between each byte
13
- # -p, --prefix=PREFIX PREFIX before each byte
14
- # -s, --suffix=SUFFIX SUFFIX after each byte
15
- #
16
2
 
17
- require 'rbkb'
18
- require 'rbkb/command_line'
19
-
20
- include RBkB::CommandLine
21
-
22
- #------------------------------------------------------------------------------
23
- # Init options and arg parsing
24
- OPTS = {}
25
- arg = bkb_stdargs(nil, OPTS)
26
- arg = bkb_inputargs(arg, OPTS)
27
-
28
- arg.banner += " <data | blank for stdin>"
29
-
30
- #------------------------------------------------------------------------------
31
- # Add local options
32
-
33
- arg.on("-l", "--length LEN", Numeric, "Hexify in lines of LEN bytes") do |l|
34
- bail("Length must be greater than zero") unless (OPTS[:len] = l) > 0
35
- end
36
-
37
- arg.on("-d", "--delim=DELIMITER", "DELIMITER between each byte") do |d|
38
- OPTS[:delim] = d
39
- end
40
-
41
- arg.on("-p", "--prefix=PREFIX", "PREFIX before each byte") do |p|
42
- OPTS[:prefix] = p
43
- end
44
-
45
- arg.on("-s", "--suffix=SUFFIX", "SUFFIX after each byte") do |s|
46
- OPTS[:suffix] = s
47
- end
48
-
49
-
50
- #------------------------------------------------------------------------------
51
- # Parse arguments
52
- arg.parse!(ARGV) rescue bail "Error: #{$!}\nUse -h|--help for more info."
53
-
54
- # original-style spacing compatability
55
- if ARGV[0] == "+" and OPTS[:delim].nil?
56
- OPTS[:delim]=" "
57
- ARGV.shift
58
- end
59
-
60
- # default string arg
61
- if OPTS[:indat].nil? and a=ARGV.shift
62
- OPTS[:indat] = a.dup
63
- end
64
-
65
- # catchall
66
- if ARGV.length != 0
67
- bail "Error: bad arguments - #{ARGV.join(' ')}\n-h|--help for more info."
68
- end
69
-
70
- # Default to standard input
71
- OPTS[:indat] ||= STDIN.read()
72
-
73
- #------------------------------------------------------------------------------
74
- # Do stuff
75
-
76
- indat = OPTS.delete(:indat)
77
- len = OPTS.delete(:len)
78
-
79
- exit 1 unless((len ||= indat.length) > 0)
80
-
81
- until (m = indat.slice!(0..len-1)).empty?
82
- print m.hexify(OPTS)
83
- puts (OPTS[:delim] and not indat.empty?)? OPTS[:delim] : "\n"
84
- end
3
+ require "rbkb/cli/hexify"
85
4
 
5
+ Rbkb::Cli::Hexify.run()
data/bin/len CHANGED
@@ -1,74 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # Author Eric Monti (emonti at matasano)
3
- #
4
- # len prepends a binary length number in front of its input and writes it
5
- # raw on STDOUT
6
- #
7
- # Usage: len [options] <data | blank for stdin>
8
- # -h, --help Show this message
9
- # -v, --version Show version and exit
10
- # -f, --file FILENAME Input from FILENAME
11
- # -n, --nudge INT Add integer to length
12
- # -s, --size=SIZE Size of length field in bytes
13
- # -x, --[no-]swap Swap endianness. Default=big
14
- # -t, --[no-]total Include size word in size
15
- # -l, --length=LEN Ignore all else and use LEN
16
- #
17
2
 
18
- require 'rbkb'
19
- require 'rbkb/command_line'
20
-
21
- include RBkB::CommandLine
22
-
23
- #-------------------------------------------------------------------------------
24
- # Init options and arg parsing
25
-
26
- # endianness pair. index 0 is always the default
27
- endpair = [:big, :little]
28
-
29
- OPTS = {:nudge => 0, :size => 4, :endian => endpair[0]}
30
-
31
- arg = bkb_stdargs(nil, OPTS)
32
- arg = bkb_inputargs(arg, OPTS)
33
-
34
- arg.banner += " <data | blank for stdin>"
35
-
36
- #------------------------------------------------------------------------------
37
- # Add local options
38
- arg.on("-n", "--nudge INT", Numeric, "Add integer to length") do |n|
39
- OPTS[:nudge] += n
40
- end
41
-
42
- arg.on("-s", "--size=SIZE", Numeric, "Size of length field in bytes") do |s|
43
- bail("Size must be greater than 0") unless (OPTS[:size] = s) > 0
44
- end
45
-
46
- arg.on("-x", "--[no-]swap", "Swap endianness. Default=#{OPTS[:endian]}") do |x|
47
- OPTS[:endian] = endpair[(x)? 1 : 0]
48
- end
49
-
50
- arg.on("-t", "--[no-]total", "Include size word in size") do |t|
51
- OPTS[:tot]=t
52
- end
53
-
54
- arg.on("-l", "--length=LEN", Numeric, "Ignore all else and use LEN") do |l|
55
- OPTS[:static]=l
56
- end
57
-
58
- #------------------------------------------------------------------------------
59
- # Parse arguments
60
- arg.parse!(ARGV) rescue bail "Error: #{$!}\n#{arg}"
61
-
62
- OPTS[:indat] ||= ARGV.shift
63
- OPTS[:indat] ||= STDIN.read
64
-
65
- bail "Error: Too many arguments\n##{arg}" if ARGV.shift
66
-
67
- unless len=OPTS[:static]
68
- len = OPTS[:indat].size
69
- len += OPTS[:size] if OPTS[:tot]
70
- len += OPTS[:nudge]
71
- end
72
-
73
- STDOUT.write len.to_bytes(OPTS[:endian], OPTS[:size]) << OPTS[:indat]
3
+ require "rbkb/cli/len"
74
4
 
5
+ Rbkb::Cli::Len.run()
data/bin/plugsrv CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+ # TODO refactor into rbkb/plug and add blit support
3
3
  #
4
4
 
5
- require 'rubygems'
6
5
  require 'eventmachine'
7
6
  require 'socket'
8
7
  require 'optparse'
@@ -13,7 +12,7 @@ def bail(*msg)
13
12
  exit 1
14
13
  end
15
14
 
16
- class Plug
15
+ class PlugSrv
17
16
  module UI
18
17
  def log( *msg )
19
18
  unless PLUG_OPTS[:quiet]
@@ -65,7 +64,7 @@ class Plug
65
64
 
66
65
  srv.controller = cli.controller = ctrl
67
66
  end
68
- end # class Plug::Controller
67
+ end # class PlugSrv::Controller
69
68
 
70
69
 
71
70
  module BaseTCP
@@ -108,7 +107,7 @@ class Plug
108
107
 
109
108
 
110
109
  module TCPListener
111
- include Plug::BaseTCP
110
+ include PlugSrv::BaseTCP
112
111
  attr_accessor :tgtaddr, :tgtport
113
112
 
114
113
  def post_init
@@ -117,7 +116,7 @@ class Plug
117
116
  @sock_peer = Socket.unpack_sockaddr_in(get_peername).reverse
118
117
  @sock_peername = @sock_peer.join(':')
119
118
 
120
- @controller = Plug::Controller.proxy(self)
119
+ @controller = PlugSrv::Controller.proxy(self)
121
120
 
122
121
  notify_connection
123
122
  end
@@ -126,7 +125,7 @@ class Plug
126
125
 
127
126
 
128
127
  module TCPClient
129
- include Plug::BaseTCP
128
+ include PlugSrv::BaseTCP
130
129
  attr_accessor :connected
131
130
 
132
131
  def post_init
@@ -142,79 +141,75 @@ class Plug
142
141
 
143
142
  end # module TCPClient
144
143
 
145
- end # module Plug
144
+ end # module PlugSrv
146
145
 
147
146
  PLUG_OPTS={ :quiet => false, :out => STDOUT }
148
147
 
149
- if __FILE__ == $0
150
-
151
-
152
- #############################################################################
153
- ### MAIN
154
- #############################################################################
155
- #
156
- # Get arguments
157
- opts = OptionParser.new do |opts|
158
- opts.banner = "Usage: #{$0} [options] target:tport[@[laddr:]lport]\n",
159
- " <target:tport> = the address of the target service\n",
160
- " <@laddr:lport> = optional address and port to listen on\n"
161
148
 
162
- opts.separator ""
163
- opts.separator "Options:"
149
+ #############################################################################
150
+ ### MAIN
151
+ #############################################################################
152
+ #
153
+ # Get arguments
154
+ opts = OptionParser.new do |opts|
155
+ opts.banner = "Usage: #{$0} [options] target:tport[@[laddr:]lport]\n",
156
+ " <target:tport> = the address of the target service\n",
157
+ " <@laddr:lport> = optional address and port to listen on\n"
164
158
 
165
- opts.on_tail("-h", "--help", "Show this message") do
166
- puts opts
167
- exit 1
168
- end
159
+ opts.separator ""
160
+ opts.separator "Options:"
169
161
 
170
- opts.on("-o", "--output FILE", "send output to a file") do |o|
171
- PLUG_OPTS[:out] = File.open(o, "w") rescue (bail $!)
172
- end
162
+ opts.on_tail("-h", "--help", "Show this message") do
163
+ puts opts
164
+ exit 1
165
+ end
173
166
 
174
- opts.on("-l", "--listen ADDR:PORT",
175
- "optional listener address:port",
176
- "(default: 0.0.0.0:<tport>)"
177
- ) do |addr|
167
+ opts.on("-o", "--output FILE", "send output to a file") do |o|
168
+ PLUG_OPTS[:out] = File.open(o, "w") rescue (bail $!)
169
+ end
178
170
 
179
- unless m = /^([\w\.]+)?(?::(\d+))?$/.match(addr)
180
- STDERR.puts "invalid listener address"
181
- exit 1
182
- end
183
- PLUG_OPTS[:svraddr] = m[1]
184
- PLUG_OPTS[:svrport] = (m[2])? m[2].to_i : nil
185
- end
171
+ opts.on("-l", "--listen ADDR:PORT",
172
+ "optional listener address:port",
173
+ "(default: 0.0.0.0:<tport>)"
174
+ ) do |addr|
186
175
 
187
- opts.on("-q", "--[no-]quiet", "Suppress/Enable conversation dumps.") do |q|
188
- PLUG_OPTS[:quiet] = q
176
+ unless m = /^([\w\.]+)?(?::(\d+))?$/.match(addr)
177
+ STDERR.puts "invalid listener address"
178
+ exit 1
189
179
  end
180
+ PLUG_OPTS[:svraddr] = m[1]
181
+ PLUG_OPTS[:svrport] = (m[2])? m[2].to_i : nil
182
+ end
190
183
 
184
+ opts.on("-q", "--[no-]quiet", "Suppress/Enable conversation dumps.") do |q|
185
+ PLUG_OPTS[:quiet] = q
191
186
  end
192
187
 
193
- opts.parse!(ARGV) rescue (STDERR.puts $!; exit 1)
188
+ end
194
189
 
190
+ opts.parse!(ARGV) rescue (STDERR.puts $!; exit 1)
195
191
 
196
- # Get target/listen argument
197
- rx = /^([\w\.]+):(\d+)(?:@(?:([\w\.]+):)?(\d+))?$/
198
- unless (m = rx.match(ARGV.shift)) and ARGV.shift.nil?
199
- $stderr.puts opts.banner
200
- exit 1
201
- end
202
192
 
203
- PLUG_OPTS[:tgtaddr] = m[1]
204
- PLUG_OPTS[:tgtport] = m[2].to_i
205
- PLUG_OPTS[:svraddr] ||= (m[3] || "0.0.0.0")
206
- PLUG_OPTS[:svrport] ||= (m[4] || PLUG_OPTS[:tgtport]).to_i
193
+ # Get target/listen argument
194
+ rx = /^([\w\.]+):(\d+)(?:@(?:([\w\.]+):)?(\d+))?$/
195
+ unless (m = rx.match(ARGV.shift)) and ARGV.shift.nil?
196
+ $stderr.puts opts.banner
197
+ exit 1
198
+ end
207
199
 
200
+ PLUG_OPTS[:tgtaddr] = m[1]
201
+ PLUG_OPTS[:tgtport] = m[2].to_i
202
+ PLUG_OPTS[:svraddr] ||= (m[3] || "0.0.0.0")
203
+ PLUG_OPTS[:svrport] ||= (m[4] || PLUG_OPTS[:tgtport]).to_i
208
204
 
209
- # Start controller
210
- ctrl = Plug::Controller.new(PLUG_OPTS[:tgtaddr], PLUG_OPTS[:tgtport], Plug::TCPClient)
211
205
 
212
- # Start event loop
213
- Plug::UI.log "%Starting TCP PlugServer #{PLUG_OPTS[:svraddr]}:#{PLUG_OPTS[:svrport]} -> #{PLUG_OPTS[:tgtaddr]}:#{PLUG_OPTS[:tgtport]}"
206
+ # Start controller
207
+ ctrl = PlugSrv::Controller.new(PLUG_OPTS[:tgtaddr], PLUG_OPTS[:tgtport], PlugSrv::TCPClient)
214
208
 
215
- EventMachine::run {
216
- EventMachine::start_server(PLUG_OPTS[:svraddr], PLUG_OPTS[:svrport], Plug::TCPListener)
217
- }
209
+ # Start event loop
210
+ PlugSrv::UI.log "%Starting TCP PlugServer #{PLUG_OPTS[:svraddr]}:#{PLUG_OPTS[:svrport]} -> #{PLUG_OPTS[:tgtaddr]}:#{PLUG_OPTS[:tgtport]}"
218
211
 
212
+ EventMachine::run {
213
+ EventMachine::start_server(PLUG_OPTS[:svraddr], PLUG_OPTS[:svrport], PlugSrv::TCPListener)
214
+ }
219
215
 
220
- end
data/bin/rstrings CHANGED
@@ -1,123 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- #
3
- # rstrings is "strings"... in ruby... with extra stuff
4
- #
5
- # Usage: rstrings [options] <file | blank for stdin>
6
- # -h, --help Show this message
7
- # -v, --version Show version and exit
8
- # -s, --start=OFFSET Start at offset
9
- # -e, --end=OFFSET End at offset
10
- # -t, --encoding-type=TYPE Encoding: ascii|unicode|both (default=both)
11
- # -l, --min-length=NUM Minimum length of strings (default=6)
12
- # -a, --align=ALIGNMENT Match only on alignment (default=none)
13
- #
14
2
 
15
- require 'rbkb'
16
- require 'rbkb/command_line'
17
-
18
- include RBkB::CommandLine
19
-
20
- #-------------------------------------------------------------------------------
21
- # Init options and arg parsing
22
- OPTS = {
23
- :start_off => 0,
24
- :end_off => -1,
25
- :encoding => :both,
26
- :minimum => 6,
27
- :align => nil,
28
- :indat => Array.new,
29
- :fnames => Array.new,
30
- }
31
-
32
- arg = bkb_stdargs(nil, OPTS)
33
-
34
- arg.banner += " <file | blank for stdin>"
35
-
36
- #------------------------------------------------------------------------------
37
- # Add local options
38
-
39
- arg.on("-s", "--start=OFFSET", "Start at offset") do |s|
40
- unless m=/^(?:(\d+)|0x([A-Fa-f0-9]+))$/.match(s)
41
- raise "invalid offset '#{s}'"
42
- end
43
- OPTS[:start_off] = (m[2])? m[0].hex : m[0].to_i
44
- end
45
-
46
- arg.on("-e", "--end=OFFSET", "End at offset") do |e|
47
- unless m=/^(?:(\d+)|0x([A-Fa-f0-9]+))$/.match(e)
48
- raise "invalid offset '#{e}'"
49
- end
50
- OPTS[:end_off] = (m[2])? m[0].hex : m[0].to_i
51
- end
52
-
53
- arg.on("-t", "--encoding-type=TYPE",
54
- "Encoding: ascii/unicode/both (default=#{OPTS[:encoding]})") do |t|
55
- OPTS[:encoding] = t.to_sym
56
- end
57
-
58
- arg.on("-l", "--min-length=NUM", Numeric,
59
- "Minimum length of strings (default=#{OPTS[:minimum]})") do |l|
60
- OPTS[:minimum] = l
61
- end
62
-
63
- arg.on("-a", "--align=ALIGNMENT", Numeric,
64
- "Match only on alignment (default=none)") do |a|
65
- (OPTS[:align] = a) > 0 or raise "bad alignment '#{a}'"
66
- end
67
-
68
-
69
- #------------------------------------------------------------------------------
70
- # Parse arguments
71
- arg.parse!(ARGV) rescue bail "Error: #{$!}\n#{arg}"
72
-
73
- # default string arg
74
- if OPTS[:indat].empty? and not ARGV.empty?
75
- while a=ARGV.shift
76
- OPTS[:indat] << File.read(a) rescue(bail "Error: Can't open '#{a}'")
77
- OPTS[:fnames] << a
78
- end
79
- end
80
-
81
- # catchall
82
- if ARGV.length != 0
83
- bail "Error: bad arguments - #{ARGV.join(' ')}\n#{arg}"
84
- end
85
-
86
- if OPTS[:indat].empty?
87
- OPTS[:indat] << STDIN.read() if OPTS[:indat].empty?
88
- OPTS[:fnames] << "[STDIN]"
89
- end
90
-
91
- #------------------------------------------------------------------------------
92
- # Do stuff
93
-
94
- start_off = OPTS[:start_off]
95
- end_off = OPTS[:end_off]
96
- enc = OPTS[:encoding]
97
- min = OPTS[:minimum]
98
- align = OPTS[:align]
99
-
100
- OPTS[:pr_fnames]=true if OPTS[:fnames].size > 1
101
-
102
- begin
103
- i=0
104
- while buf=OPTS[:indat].shift
105
- buf[start_off..end_off].strings(
106
- :encoding => enc,
107
- :minimum => min,
108
- :align => align
109
- ) do |off, len, type, str|
110
- if OPTS[:pr_fnames]
111
- print "#{OPTS[:fnames][i]}:"
112
- end
113
- puts "#{(off+start_off).to_hex.rjust(8,"0")}:"+
114
- "#{(len+start_off).to_hex.rjust(8,"0")}:"+
115
- "#{type.to_s[0,1]}:#{str.delete("\000").inspect}"
116
- end
117
- i+=1
118
- end
119
- rescue
120
- # STDERR.puts $!
121
- # exit 1
122
- end
3
+ require "rbkb/cli/rstrings"
123
4
 
5
+ Rbkb::Cli::Rstrings.run()
data/bin/slice CHANGED
@@ -1,74 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # (emonti at matasano) Matasano Security LLC
3
- #
4
- # slice.rb : returns a slice from input
5
- # just a shell interface to a string slice operation
6
- #
7
- # Usage: slice [options] start (no args when using -r|-x)
8
- # -h, --help Show this message
9
- # -v, --version Show version and exit
10
- # -f, --file FILENAME Input from FILENAME
11
- # -r, --range=START[:END] Start and optional end range
12
- # -x, --hexrange=START[:END] same, but in hex
13
- #
14
2
 
15
- require 'rbkb'
16
- require 'rbkb/command_line'
17
-
18
- include RBkB::CommandLine
19
-
20
- OPTS = {:last => -1}
21
- arg = bkb_stdargs(nil, OPTS)
22
- arg = bkb_inputargs(arg, OPTS)
23
-
24
- arg.banner += " start (no args when using -r|-x|)"
25
-
26
- arg.on("-r", "--range=START[:END]", "Start and optional end range") do |r|
27
-
28
- raise "-x and -r are mutually exclusive" if OPTS[:first]
29
-
30
- unless m=/^(-?[0-9]+)(?::(-?[0-9]+))?$/.match(r)
31
- raise "invalid range #{r.inspect}"
32
- end
33
-
34
- OPTS[:first] = $1.to_i
35
- OPTS[:last] = $2.to_i if $2
36
- end
37
-
38
- arg.on("-x", "--hexrange=START[:END]", "same, but in hex") do |r|
39
-
40
- raise "-x and -r are mutually exclusive" if OPTS[:first]
41
-
42
- unless m=/^(-?[0-9a-f]+)(?::(-?[0-9a-f]+))?$/i.match(r)
43
- raise "invalid range #{r.inspect}"
44
- end
45
-
46
- OPTS[:first]=($1[0,1] == '-')? ($1[1..-1]).hex_to_num * -1 : $1.hex_to_num
47
- if $2
48
- OPTS[:last]=($2[0,1] == '-')? ($2[1..-1]).hex_to_num * -1 : $2.hex_to_num
49
- end
50
- end
51
-
52
- begin
53
- arg.parse!
54
-
55
- OPTS[:first] ||= ARGV.shift
56
-
57
- unless( ARGV.length != 1 and (
58
- OPTS[:first].kind_of?(Numeric) or
59
- /^-?\d+$/.match(OPTS[:first]) )
60
- )
61
- raise "bad arguments"
62
- end
63
-
64
- OPTS[:first] = OPTS[:first].to_i
65
-
66
- OPTS[:indat] ||= STDIN.read()
67
-
68
- # drumroll... and substring:
69
- STDOUT.write OPTS[:indat][ OPTS[:first] .. OPTS[:last] ]
70
-
71
- rescue
72
- bail "Error: #{$!}\n#{arg}"
73
- end
3
+ require "rbkb/cli/slice"
74
4
 
5
+ Rbkb::Cli::Slice.run()
data/bin/telson CHANGED
@@ -1,109 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # telson <emonti at matasano> 3/15/2008
3
- #----------------------------------------------------------------------
4
- #
5
- # This is an implementation of the original blackbag "telson" around
6
- # ruby and eventmachine.
7
- #
8
- # Telson can do the following things with minimum fuss:
9
- # - Run as a server or client using UDP or TCP
10
- # - Debugging network protocols
11
- # - Observe client/server behaviors using different messages at
12
- # various phases of a conversation.
13
- #
14
- #----------------------------------------------------------------------
15
- #
16
- # Usage: telson -h
17
- #
18
2
 
19
- require 'rbkb'
20
- require 'rbkb/plug'
21
- require 'rbkb/command_line'
22
-
23
- include RBkB::CommandLine
24
-
25
- Plug::UI::LOGCFG[:verbose] = true
26
- Plug::UI::LOGCFG[:dump] = :hex
27
-
28
-
29
- b_addr = Plug::Blit::DEFAULT_IPADDR
30
- b_port = Plug::Blit::DEFAULT_PORT
31
-
32
- srced = persist = false
33
-
34
- s_addr = "0.0.0.0"
35
- s_port = 0
36
-
37
- proto = :TCP
38
-
39
- arg = bkb_stdargs(nil, {})
40
- arg.banner += " host:port"
41
-
42
- arg.on("-u", "--udp", "UDP mode") do
43
- proto=:UDP
44
- end
45
-
46
- arg.on("-b", "--blit=ADDR:PORT", "Where to listen for blit") do |b|
47
- unless m=/^(?:([\w\.]+):)?(\d+)$/.match(b)
48
- raise "invalid blit address/port"
49
- end
50
- b_port = m[2].to_i
51
- b_addr = m[1] if m[1]
52
- end
53
-
54
- arg.on("-o", "--output=FILE", "Output to file instead of screen") do |f|
55
- Plug::UI::LOGCFG[:out] = File.open(f, "w")
56
- end
57
-
58
- arg.on("-q", "--quiet", "Turn off verbose logging") do
59
- Plug::UI::LOGCFG[:verbose] = false
60
- end
61
-
62
- arg.on("-r", "--reconnect", "Attempt to reconnect endlessly.") do
63
- persist=true
64
- end
65
-
66
- arg.on("-s", "--source=(ADDR:?)PORT", "Bind on port (and addr?)") do |p|
67
- if m=/^(?:([\w\.]+):)?(\d+)$/.match(p)
68
- s_addr = $1 if $1
69
- s_port = $2.to_i
70
- srced = true
71
- else
72
- raise "Invalid listen argument: #{p.inspect}"
73
- end
74
- end
75
-
76
-
77
- arg.parse!(ARGV) rescue bail "Error: #{$!}\nUse -h|--help for more info."
78
-
79
- # Get target argument
80
- unless (m = /^([\w\.]+):(\d+)$/.match(ARGV.shift)) and ARGV.shift.nil?
81
- bail arg
82
- end
83
-
84
- t_addr = m[1]
85
- t_port = m[2].to_i
86
-
87
- loop do
88
- EventMachine.run {
89
- if proto == :TCP
90
- bail "Sorry: --source only works with UDP. Blame EventMachine!" if srced
91
-
92
- c=EventMachine.connect(t_addr, t_port, Plug::Telson, proto)
93
-
94
- elsif proto == :UDP
95
- c=EventMachine.open_datagram_socket(s_addr, s_port, Plug::Telson, proto)
96
- c.peers.add_peer_manually(t_addr, t_port)
97
-
98
- ### someday maybe raw or others?
99
- else
100
- raise "bad protocol"
101
- end
102
-
103
- EventMachine.start_server(b_addr, b_port, Plug::Blit, :TCP, c)
104
- Plug::UI::verbose("** BLITSRV-#{b_addr}:#{b_port}(TCP) Started")
105
- }
106
- break unless persist
107
- Plug::UI::verbose("** RECONNECTING")
108
- end
3
+ require "rbkb/cli/telson"
109
4
 
5
+ Rbkb::Cli::Telson.run()