command_lion 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cee05e4f0555f83fb7dffe36f7c28e6ca8603aa5
4
- data.tar.gz: 6c3c462a11454e503033a4af744bec9132454b1f
3
+ metadata.gz: 91313ee91c191e8a8f0b492a5b6f0f603e3ae8b2
4
+ data.tar.gz: 18bac0196033a11566c923b933b2f47d161575ac
5
5
  SHA512:
6
- metadata.gz: da7d776824f0b1ba28da9cbc1085662f7d3ef1d9b757bf47ae9cbb9722de1b2089000d4898ec4827f7fa9facb67ebc3d8efdf29b7ebaddb358fbae956c579c6b
7
- data.tar.gz: 1743834b1f7b78e3e45c2fc282a588b6e234de7c2a8cffcb035758016af72a30c0f2412179ade2b1d050cb3789e968773a9d9685d099d5ad67dbbf176ac77c03
6
+ metadata.gz: 14ef85bc5916f07d98adc9a553f623acfdcabdc51b5ada2eaeed1758eda824b8e518a6d2b3db36010a04219921d2ef05d1df1915cf2196f612c2152070963b7a
7
+ data.tar.gz: 467f4cefb3d55ec0d0990b10bbb01e54a223ba84fad25e9ae120a69178ac474ab4a0c32fcf0fbb1e7f93699439adc54fdbcc3724906ce431b3c45b5b94634c78
@@ -0,0 +1,49 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'command_lion'
3
+ require 'packetgen'
4
+ require 'pry'
5
+
6
+ CommandLion::App.run do
7
+
8
+ name "Packet Head"
9
+ version "1.0.0"
10
+ description "Streaming captured packet headers straight to the command-line."
11
+
12
+ command :capture do
13
+ description "Capture from a given network interface ( default: #{Pcap.lookupdev} )."
14
+ type :string
15
+ default Pcap.lookupdev
16
+
17
+ action do
18
+ capture = Pcap.open_live(argument, options[:snaplen].argument, options[:promisc].argument, options[:buffer].argument)
19
+ loop do
20
+ while packet = capture.next
21
+ begin
22
+ puts PacketGen.parse(packet).headers.map(&:class).map {|h| h.to_s.split("::").last }.join(" - ")
23
+ rescue # some error, yolo
24
+ next
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ option :snaplen do
31
+ default 65535
32
+ type :integer
33
+ description "Amount of data for each frame that is actually captured."
34
+ end
35
+
36
+ option :promisc do
37
+ type :bool
38
+ default true
39
+ description "Capture all traffic received rather than only the frames the controller is meant to receive."
40
+ end
41
+
42
+ option :buffer do
43
+ type :integer
44
+ default 1
45
+ description "Read time out in milliseconds when capturing packets, and a value of 0 means no time out."
46
+ end
47
+ end
48
+
49
+ end
data/examples/pcapr.rb ADDED
@@ -0,0 +1,45 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'command_lion'
3
+ require 'packetgen'
4
+ require 'pry'
5
+
6
+ CommandLion::App.run do
7
+
8
+ name "Pcapr"
9
+ version "1.0.0"
10
+ description "Pcaprub command-line application to capture network traffic."
11
+
12
+ command :capture do
13
+ description "Capture from a given network interface ( default: #{Pcap.lookupdev} )."
14
+ type :string
15
+ default Pcap.lookupdev
16
+
17
+ action do
18
+ capture = Pcap.open_live(argument, options[:snaplen].argument, options[:promisc].argument, options[:buffer].argument)
19
+ loop do
20
+ if packet = capture.next
21
+ puts packet
22
+ end
23
+ end
24
+ end
25
+
26
+ option :snaplen do
27
+ default 65535
28
+ type :integer
29
+ description "Amount of data for each frame that is actually captured."
30
+ end
31
+
32
+ option :promisc do
33
+ type :bool
34
+ default true
35
+ description "Capture all traffic received rather than only the frames the controller is meant to receive."
36
+ end
37
+
38
+ option :buffer do
39
+ type :integer
40
+ default 1
41
+ description "Read time out in milliseconds when capturing packets, and a value of 0 means no time out."
42
+ end
43
+ end
44
+
45
+ end
@@ -110,10 +110,13 @@ module CommandLion
110
110
  end
111
111
  puts "#{short_long} #{command.description}"
112
112
  if command.options?
113
- #binding.pry
114
113
  command.options.each do |_, option|
115
- short = option.flags.long? ? option.flags.short + ", " : option.flags.short
116
- short_long = " " + "#{short}#{option.flags.long}".ljust(max_flag - 2)
114
+ if option.flags?
115
+ short = option.flags.long? ? option.flags.short + ", " : option.flags.short
116
+ short_long = " " + "#{short}#{option.flags.long}".ljust(max_flag - 2)
117
+ else
118
+ short_long = " " + "#{option.index.to_s}".ljust(max_flag - 2)
119
+ end
117
120
  puts "#{short_long} #{option.description}"
118
121
  end
119
122
  end
@@ -210,9 +213,14 @@ module CommandLion
210
213
  end
211
214
  if cmd.options?
212
215
  cmd.options.each do |_, option|
213
- @flags << option.flags.short if cmd.flags.short?
214
- @flags << option.flags.long if cmd.flags.long?
215
- @commands << option
216
+ if option.flags?
217
+ @flags << option.flags.short if cmd.flags.short?
218
+ @flags << option.flags.long if cmd.flags.long?
219
+ else # just use index
220
+ @flags << option.index.to_s
221
+ end
222
+ @commands[option.index] = option
223
+ #@commands << option
216
224
  end
217
225
  end
218
226
  @commands[cmd.index] = cmd
@@ -259,9 +267,13 @@ module CommandLion
259
267
 
260
268
  # Parse a given command with its
261
269
  def parse_cmd(cmd, flags)
262
- args = Raw.arguments_to(cmd.flags.short, flags)
263
- if args.empty?
264
- args = Raw.arguments_to(cmd.flags.long, flags)
270
+ if cmd.flags?
271
+ args = Raw.arguments_to(cmd.flags.short, flags)
272
+ if args.empty?
273
+ args = Raw.arguments_to(cmd.flags.long, flags)
274
+ end
275
+ else
276
+ args = Raw.arguments_to(cmd.index.to_s, flags)
265
277
  end
266
278
  return nil if args.nil?
267
279
  case cmd.type
@@ -1,3 +1,3 @@
1
1
  module CommandLion
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_lion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kent 'picat' Gruber
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-28 00:00:00.000000000 Z
11
+ date: 2017-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,6 +84,8 @@ files:
84
84
  - examples/hello_world.rb
85
85
  - examples/key_value_example.rb
86
86
  - examples/numbers.txt
87
+ - examples/packet_head.rb
88
+ - examples/pcapr.rb
87
89
  - examples/plugin.rb
88
90
  - examples/read_file.rb
89
91
  - examples/read_stdin.rb