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 +4 -4
- data/examples/packet_head.rb +49 -0
- data/examples/pcapr.rb +45 -0
- data/lib/command_lion/app.rb +21 -9
- data/lib/command_lion/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91313ee91c191e8a8f0b492a5b6f0f603e3ae8b2
|
4
|
+
data.tar.gz: 18bac0196033a11566c923b933b2f47d161575ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/command_lion/app.rb
CHANGED
@@ -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
|
-
|
116
|
-
|
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
|
-
|
214
|
-
|
215
|
-
|
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
|
-
|
263
|
-
|
264
|
-
args
|
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
|
data/lib/command_lion/version.rb
CHANGED
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.
|
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-
|
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
|