l-tools 0.1.0
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 +7 -0
- data/Gemfile +4 -0
- data/l-tools.gemspec +25 -0
- data/lib/l-tools.rb +23 -0
- data/lib/tools/nmap.rb +15 -0
- data/lib/tools/tool.rb +87 -0
- data/lib/tools/tshark.rb +26 -0
- data/lib/version.rb +4 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6b1063afdbce52f7818b2c92a309e3da1b54e5a1ec7d4154a20c85b4aa79b91a
|
4
|
+
data.tar.gz: 0f3fb4ce31530c0cb1c47cc0cbcc104511b94ad2fc1dd71e18fa8c5a952a0295
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b49a9dd21f82376911ab47ad3e4d0df979d17c5336b431e8ae02fbe06e2787d2716e39e234261d42dfc30295429d7085639a8bea6a2d86759119205b220f1f60
|
7
|
+
data.tar.gz: 315e21b34ac6b0610820469f2bdfe8c4cca56602622e3c59db01f855eb0efe8cd2e952fb019f54e54d09379a001c7547e967656e54cf409b190e2eee7f4f1a38
|
data/Gemfile
ADDED
data/l-tools.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require "version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "l-tools"
|
9
|
+
spec.version = LTools::VERSION
|
10
|
+
spec.authors = ["L"]
|
11
|
+
spec.email = ["l-codes@qq.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{L Tools}
|
14
|
+
spec.description = %q{Controlling external programs running}
|
15
|
+
spec.homepage = "https://github.com/l-codes/l-tools"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
25
|
+
end
|
data/lib/l-tools.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module LTools
|
4
|
+
autoload :Tool, './tools/tool'
|
5
|
+
autoload :Tshark, './tools/tshark'
|
6
|
+
autoload :Nmap, './tools/nmap'
|
7
|
+
|
8
|
+
@tools = []
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :verbose
|
12
|
+
|
13
|
+
def add_tool(tool)
|
14
|
+
@tools << tool
|
15
|
+
end
|
16
|
+
|
17
|
+
def check_all?
|
18
|
+
@tools.map do |child_class|
|
19
|
+
child_class.check?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/tools/nmap.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
module LTools
|
3
|
+
class Nmap < Tool
|
4
|
+
@name = 'nmap'
|
5
|
+
|
6
|
+
def self.portscan(targets, ports: nil, mode: 'S', speed: 5, append: nil)
|
7
|
+
cmd = "nmap -Pn -n -T#{speed} -s#{mode}"
|
8
|
+
cmd << " -p #{ports} " if ports
|
9
|
+
targets = targets.join(' ') if targets.is_a? Array
|
10
|
+
cmd << targets
|
11
|
+
cmd << append if append
|
12
|
+
new cmd
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/tools/tool.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
|
2
|
+
require 'forwardable'
|
3
|
+
require 'childprocess'
|
4
|
+
require 'colorize'
|
5
|
+
|
6
|
+
ChildProcess.posix_spawn = true
|
7
|
+
|
8
|
+
module LTools
|
9
|
+
autoload :Shellwords, 'shellwords'
|
10
|
+
|
11
|
+
class Tool
|
12
|
+
extend Forwardable
|
13
|
+
|
14
|
+
attr_reader :stdin, :stdout, :stderr
|
15
|
+
attr_accessor :verbose
|
16
|
+
|
17
|
+
def_delegators :@process, :stop, :pid, :exited?, \
|
18
|
+
:alive?, :exit_code, :poll_for_exit
|
19
|
+
|
20
|
+
def initialize(*args)
|
21
|
+
tool, *args = args
|
22
|
+
|
23
|
+
# 检测参数类型进行变换,支持一下格式:
|
24
|
+
# args = 'echo 1231'
|
25
|
+
# args = ['echo', '1231']
|
26
|
+
# args = [['echo', '1231']]
|
27
|
+
case tool
|
28
|
+
when String
|
29
|
+
if args.empty? and tool.include? ' '
|
30
|
+
tool, *args = Shellwords.split(tool)
|
31
|
+
end
|
32
|
+
when Array
|
33
|
+
tool, *args = tool
|
34
|
+
else
|
35
|
+
raise
|
36
|
+
end
|
37
|
+
|
38
|
+
@cmd = args.unshift(tool).map(&:to_s)
|
39
|
+
@process = ChildProcess.build(*@cmd)
|
40
|
+
|
41
|
+
@stdout, @stdout_w = IO.pipe
|
42
|
+
@process.io.stdout = @stdout_w
|
43
|
+
|
44
|
+
@stderr, @stderr_w = IO.pipe
|
45
|
+
@process.io.stderr = @stderr_w
|
46
|
+
|
47
|
+
@verbose = true if LTools.verbose
|
48
|
+
end
|
49
|
+
|
50
|
+
def start
|
51
|
+
@process.duplex = true unless @inherit
|
52
|
+
@process.start
|
53
|
+
@stdin = @process.io.stdin unless @inherit
|
54
|
+
if @verbose
|
55
|
+
puts "[#{'+'.light_green.bold}] #{self.class.to_s.light_yellow} (pid: #{pid})"
|
56
|
+
puts " #{?$.light_red.bold} #{@cmd.join(' ')}"
|
57
|
+
puts
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def wait
|
62
|
+
@process.wait
|
63
|
+
@stdout_w.close
|
64
|
+
@stderr_w.close
|
65
|
+
end
|
66
|
+
|
67
|
+
def stop
|
68
|
+
@process.stop
|
69
|
+
@stdout_w.close
|
70
|
+
@stderr_w.close
|
71
|
+
end
|
72
|
+
|
73
|
+
def io_inherit!
|
74
|
+
@inherit = true
|
75
|
+
@process.io.inherit!
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.inherited(child_class)
|
79
|
+
LTools.add_tool(child_class)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.check?
|
83
|
+
system "hash #{@name} 2>&-"
|
84
|
+
$?.success?
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/tools/tshark.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
module LTools
|
3
|
+
class Tshark < Tool
|
4
|
+
@name = 'tshark'
|
5
|
+
|
6
|
+
def self.capture(interface: nil, bpf: nil, fields:nil, filter: nil, append: nil)
|
7
|
+
cmd = 'tshark'
|
8
|
+
cmd << " -i '#{interface}'" if interface
|
9
|
+
cmd << " -f '#{bpf}'" if bpf
|
10
|
+
cmd << " -Y '#{filter}'" if filter
|
11
|
+
if fields
|
12
|
+
fields = fields.split if fields.is_a? String
|
13
|
+
fields.unshift ' -T fields'
|
14
|
+
cmd << fields.join(' -e ')
|
15
|
+
end
|
16
|
+
cmd << append if append
|
17
|
+
new cmd
|
18
|
+
end
|
19
|
+
|
20
|
+
def records
|
21
|
+
@stdout.each_line.map do |line|
|
22
|
+
line.split("\t")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: l-tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- L
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
description: Controlling external programs running
|
28
|
+
email:
|
29
|
+
- l-codes@qq.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- Gemfile
|
35
|
+
- l-tools.gemspec
|
36
|
+
- lib/l-tools.rb
|
37
|
+
- lib/tools/nmap.rb
|
38
|
+
- lib/tools/tool.rb
|
39
|
+
- lib/tools/tshark.rb
|
40
|
+
- lib/version.rb
|
41
|
+
homepage: https://github.com/l-codes/l-tools
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.7.7
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: L Tools
|
65
|
+
test_files: []
|