syspy 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/syspy +2 -0
  2. data/lib/syspy.rb +2 -0
  3. data/lib/tds_package_stream.rb +26 -23
  4. metadata +52 -30
data/bin/syspy CHANGED
@@ -1,3 +1,5 @@
1
+ $:.unshift File.join(File.dirname(File.dirname(__FILE__)),"lib")
2
+
1
3
  require "rubygems"
2
4
  require "syspy"
3
5
  require "time"
data/lib/syspy.rb CHANGED
@@ -1,3 +1,5 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
1
3
  require "rubygems"
2
4
  require "log"
3
5
  require "tds_package_stream"
@@ -17,23 +17,33 @@ module Syspy
17
17
 
18
18
  def each_package()
19
19
  Thread.abort_on_exception = true
20
- @tcpdump_thread = Thread.new(){
21
- IO.popen("tcpdump -q -y EN10MB -U -B 2048 -w - -i #{@interface} tcp and dst #{@dst} and dst port #{@dst_port} 2>/dev/null"){|io|
22
- content = ""
23
- loop(){
24
- tcp_length = read_ip_header(io)
25
- Log.debug "Got IP package: #{tcp_length}"
26
- content_length = read_tcp_header(io,tcp_length)
27
- Log.debug "Got TCP package: #{content_length}"
28
-
29
- if(content_length > 0)
30
- content = io.read(content_length)
31
- @out.write(content)
32
- @out.flush
20
+ @tcpdump_thread = Thread.new(){
21
+ IO.popen("tcpdump -B 2048 -q -x -i #{@interface} tcp and dst #{@dst} and dst port #{@dst_port} 2>/dev/null"){|io|
22
+ buffer = StringIO.new()
23
+ io.each_line(){|line|
24
+ if(line.match(/^\d{1,2}:\d{1,2}:\d{1,2}.+$/))
25
+ puts line
26
+ unless(buffer.string.empty?)
27
+ data_io = StringIO.new(buffer.string)
28
+ tcp_length = read_ip_header(data_io)
29
+ Log.debug "Got IP package: #{tcp_length}"
30
+ content_length = read_tcp_header(data_io,tcp_length)
31
+ Log.debug "Got TCP package: #{content_length}"
32
+ if(content_length > 0)
33
+ content = data_io.read(content_length)
34
+ @out.write(content)
35
+ @out.flush
36
+ end
37
+ buffer = StringIO.new()
38
+ end
39
+ else
40
+ token = line.squeeze(" ").split(" ")[1..-1].join("")
41
+ 0.upto((token.size / 2) - 1){|i|
42
+ char = token[i*2,2].to_i(16)
43
+ buffer.putc(char)
44
+ }
33
45
  end
34
-
35
- Log.debug "Network package done"
36
- }
46
+ }
37
47
  }
38
48
  }
39
49
 
@@ -80,13 +90,6 @@ module Syspy
80
90
  end
81
91
 
82
92
  def read_ip_header(io)
83
- count = 0
84
- loop(){
85
- network_type = Bytes.uint16be(io)
86
- break if network_type == 0x800 and count >= 14
87
- count += 1
88
- }
89
-
90
93
  # read IP version and header length
91
94
  ver_len = Bytes.uint(io)
92
95
  version = ver_len >> 4
metadata CHANGED
@@ -1,34 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: syspy
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.17
3
+ version: !ruby/object:Gem::Version
4
+ hash: 59
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 18
10
+ version: 0.0.18
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Matthias Balmer
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-01-23 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-02-14 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: bindata
16
- requirement: &12454940 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
17
25
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
22
33
  type: :runtime
23
- prerelease: false
24
- version_requirements: *12454940
34
+ version_requirements: *id001
25
35
  description:
26
36
  email: matthias.balmer@sysinf.ch
27
- executables:
37
+ executables:
28
38
  - syspy
29
39
  extensions: []
40
+
30
41
  extra_rdoc_files: []
31
- files:
42
+
43
+ files:
32
44
  - lib/bytes.rb
33
45
  - lib/tds_types.rb
34
46
  - lib/tds_tokens.rb
@@ -41,29 +53,39 @@ files:
41
53
  - lib/syspy.rb
42
54
  - lib/tds_package.rb
43
55
  - bin/syspy
56
+ has_rdoc: true
44
57
  homepage:
45
58
  licenses: []
46
- post_install_message: To use syspy as standalone application run "sudo syspy <interface>
47
- <destination_ip> <destination_port>"
59
+
60
+ post_install_message: To use syspy as standalone application run "sudo syspy <interface> <destination_ip> <destination_port>"
48
61
  rdoc_options: []
49
- require_paths:
62
+
63
+ require_paths:
50
64
  - lib
51
- required_ruby_version: !ruby/object:Gem::Requirement
65
+ required_ruby_version: !ruby/object:Gem::Requirement
52
66
  none: false
53
- requirements:
54
- - - ! '>='
55
- - !ruby/object:Gem::Version
56
- version: '0'
57
- required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
75
  none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
63
83
  requirements: []
84
+
64
85
  rubyforge_project:
65
- rubygems_version: 1.8.11
86
+ rubygems_version: 1.4.2
66
87
  signing_key:
67
88
  specification_version: 3
68
89
  summary: Observe TDS packages directly from a network interface
69
90
  test_files: []
91
+