tcpdump-ruby 0.0.2

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/os.rb +6 -0
  3. data/lib/tcpdump.rb +101 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 836b64d2006622ca7216e47ae76cc3aee71334c2
4
+ data.tar.gz: 886b2977868d700f7618c58cb7f6d43ff0c97c54
5
+ SHA512:
6
+ metadata.gz: a05a691332a78aad7b260713c0c38f4e69c29d1113143b690b17ae92569aab577571b2b4a10f13387af388c8af294c64016036d935b1152826b4663f63fa7bd5
7
+ data.tar.gz: eb7a858bae713fdf55e3517721f77e82e8e4a110a55da44fa0a49e5c7696097fa546a4b13b9fff1b95f4349fcac0a7957605512e1a92ca72c39d44ecc9b9438f
data/lib/os.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'rbconfig'
2
+
3
+ class TCPdump
4
+ def os
5
+ end
6
+ end
data/lib/tcpdump.rb ADDED
@@ -0,0 +1,101 @@
1
+ # Copyright (C) 2015, Harichandan Pulagam
2
+
3
+ class TCPDump
4
+ def self.initialize
5
+ @options = {
6
+ print_each_packet: nil, # -A
7
+ print_asdot: nil, # -b
8
+ set_buffer_size: nil, # -B
9
+ exit_after_count: nil, # -c
10
+ check_file_size: nil, # -C
11
+ dump_human_readable: nil, # -d
12
+ dump_c_program_fragment: nil, # -dd
13
+ dump_decimal_numbers: nil, # -ddd
14
+ list_interfaces: nil, # -D, --list-interfaces
15
+ print_link_layer_header: nil, # -e
16
+ print_ip_numeric: nil, # -f
17
+ file_filter_expression: nil, # -F
18
+ avoid_line_break: nil, # -g
19
+ rotate_seconds: nil, # -G
20
+ version: nil, # -h, --help, --version
21
+ interface: nil, # -i, --interface
22
+ monitor_mode: nil, # -I, --monitor-mode
23
+ absolute_seq_num: nil, # -S, --absolute-tcp-sequence-numbers
24
+ type: nil, # -T
25
+ }
26
+ tcpdump_check
27
+ end
28
+
29
+ # Check if user is root
30
+ # tcpdump needs CAP_NET_RAW and CAP_NET_ADMIN capabilites
31
+ # TO-DO allow non-root user with the above capabilities
32
+ def self.root_check
33
+ fail 'Must run as root' unless Process.uid == 0
34
+ end
35
+
36
+ # Check if tcpdump is installed
37
+ def self.tcpdump_installed?
38
+ ENV['PATH'].split(':').each do |path|
39
+ exe = File.join(path, 'tcpdump')
40
+ return true if File.executable?(exe)
41
+ end
42
+ nil
43
+ end
44
+
45
+ # Raise error if tcpdump is not installed
46
+ def self.tcpdump_check
47
+ fail 'tcpdump CLI tool should be installed' unless tcpdump_installed?
48
+ end
49
+
50
+ def self.tcpdump
51
+ root_check unless @options[:version]
52
+ command = build_command(@options)
53
+ puts "Running command: #{command}"
54
+ system(command)
55
+ end
56
+
57
+ def self.binary
58
+ 'tcpdump'
59
+ end
60
+
61
+ def self.build_command(config)
62
+ cmd = binary
63
+ cmd << option_list(config)
64
+ end
65
+
66
+ def self.set_options(hash)
67
+ hash.each { |k, v| @options[k] = v }
68
+ end
69
+
70
+ def self.option_list(config)
71
+ options_list = '';
72
+ options_list << ' -A' if config[:print_each_packet]
73
+ options_list << ' -b' if config[:print_asdot]
74
+ options_list << " -B #{config[:set_buffer_size]}" if config[:set_buffer_size]
75
+ options_list << " -c #{config[:exit_after_count]}" if config[:exit_after_count]
76
+ options_list << " -C #{config[:check_file_size]}" if config[:check_file_size]
77
+ options_list << ' -d' if config[:dump_human_readable]
78
+ options_list << ' -dd' if config[:dump_c_program_fragment]
79
+ options_list << ' -ddd' if config[:dump_decimal_numbers]
80
+ options_list << ' -D' if config[:list_interfaces]
81
+ options_list << ' -e' if config[:print_link_layer_header]
82
+ options_list << ' -f' if config[:print_ip_numeric]
83
+ options_list << ' -F' if config[:file_filter_expression]
84
+ options_list << ' -g' if config[:avoid_line_break]
85
+ options_list << " -G #{config[:rotate_seconds]}" if config[:rotate_seconds]
86
+ options_list << ' -h' if config[:version]
87
+ options_list << " -i #{config[:interface]}" if config[:interface]
88
+ options_list << ' -I' if config[:monitor_mode]
89
+ options_list << ' -S' if config[:absolute_seq_num]
90
+ options_list << " -T #{config[:type]}" if config[:type]
91
+ options_list
92
+ end
93
+
94
+ def self.get_current_config
95
+ @options
96
+ end
97
+
98
+ def self.print_current_config
99
+ puts @options
100
+ end
101
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tcpdump-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Harichandan Pulagam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: pharic.15@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/os.rb
20
+ - lib/tcpdump.rb
21
+ homepage:
22
+ licenses:
23
+ - Apache 2.0
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.5
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Ruby Wrapper for tcpdump
45
+ test_files: []