redhound 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6935c5774360fee584469172ce32fb3d5d75d9c6afac07471d6f81a1c2abeab
4
- data.tar.gz: 98f8c7e7e2910174326df83669f9f2d48e3fbabed8ce74083e060299fd95b724
3
+ metadata.gz: 1f9c914cea67f4e0f32f6dcf84149039eb95f1f2311bd6f410641b67b81d441f
4
+ data.tar.gz: ac1012da2b103d27bb43d98ca273567efc44fa4995de92af315370f73a899dc8
5
5
  SHA512:
6
- metadata.gz: 17a0eb8f7d9cf19e20c2e44a98c23054aaedc51e1fac0d314b4832c85a3c586d68057a3367887beb8a33ac41b27c1746569510cc4da874bf23ab92b130fe0c7c
7
- data.tar.gz: 0c3cae42594bfc3e341885efb840212b6d1e36b39c7ef53ece6dddb7ad59fc97d59842d9397fe82ae2f7b1f9ad3775d4e493c9987611058b85b65d4d40e405b5
6
+ metadata.gz: 4c26cd6fea83dcbd1f60e2615a8070f60ccb036f506f9a46c77d0f935a57027ddf19d7f408271dccc8a31cc3d9624b6e6db62b252bd9b6393de858819a2855c9
7
+ data.tar.gz: 4ce4cf820846e2e652bfa33a16d08ca942eb1739d0f29a04a18389fb6d992b9ab4b13504de5d5684ab67f753bc02cc94a1c9cd702dcc922b95b2de5a7a9983a8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2025-01-03
4
+
5
+ - Add option to write packets to file as PCAP Capture File Format.
6
+
3
7
  ## [0.1.0] - 2024-11-05
4
8
 
5
9
  - Initial release
data/README.md CHANGED
@@ -20,11 +20,20 @@ gem install redhound
20
20
  ## Usage
21
21
 
22
22
  ```command
23
+ ___ ____ __
24
+ / _ \___ ___/ / / ___ __ _____ ___/ /
25
+ / , _/ -_) _ / _ \/ _ \/ // / _ \/ _ /
26
+ /_/|_|\__/\_,_/_//_/\___/\_,_/_//_/\_,_/
27
+
28
+ Version: 0.1.0
29
+ Dump and analyze network packets.
30
+
23
31
  Usage: redhound [options] ...
24
32
 
25
33
  Options:
26
34
  -i, --interface INTERFACE name or idx of interface
27
35
  -D, --list-interfaces print list of interfaces and exit
36
+ -w FILE write packets to a pcap capture file format to file
28
37
  -h, --help display this help and exit
29
38
  -v, --version display version information and exit
30
39
  ```
@@ -15,7 +15,7 @@ module Redhound
15
15
  warn 'Error: interface is required'
16
16
  exit 1
17
17
  end
18
- Receiver.run(ifname: @options[:ifname])
18
+ Receiver.run(ifname: @options[:ifname], filename: @options[:filename])
19
19
  end
20
20
 
21
21
  def parse(argv)
@@ -39,6 +39,7 @@ module Redhound
39
39
  list_interfaces
40
40
  exit
41
41
  end
42
+ o.on('-w FILE', 'write packets to a pcap capture file format to file') { |v| @options[:filename] = v }
42
43
  o.on('-h', '--help', 'display this help and exit') do
43
44
  puts o
44
45
  exit
@@ -18,7 +18,6 @@ module Redhound
18
18
  end
19
19
 
20
20
  def generate
21
- pp @bytes[0..5]
22
21
  @dhost = @bytes[0..5]
23
22
  @shost = @bytes[6..11]
24
23
  @type = @bytes[12..13]
@@ -5,20 +5,28 @@ require 'socket'
5
5
  module Redhound
6
6
  class Receiver
7
7
  class << self
8
- def run(ifname:)
9
- new(ifname:).run
8
+ def run(ifname:, filename:)
9
+ new(ifname:, filename:).run
10
10
  end
11
11
  end
12
12
 
13
- def initialize(ifname:)
13
+ def initialize(ifname:, filename:)
14
14
  @ifname = ifname
15
15
  @socket = SocketBuilder.build(ifname:)
16
+ if filename
17
+ @writer = Writer.new(filename:)
18
+ @writer.start
19
+ end
16
20
  end
17
21
 
18
22
  def run
19
23
  loop do
20
24
  msg, = @socket.recvfrom(2048)
21
25
  Analyzer.analyze(msg:)
26
+ @writer.write(msg) if @writer
27
+ rescue Interrupt
28
+ @writer.stop if @writer
29
+ break
22
30
  end
23
31
  end
24
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Redhound
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Redhound
4
+ class Writer
5
+ def initialize(filename:)
6
+ @filename = filename
7
+ end
8
+
9
+ def start
10
+ @file = File.open(@filename, 'wb')
11
+ @file.write(file_header)
12
+ end
13
+
14
+ def write(msg)
15
+ @file.write(packet_record(Time.now, msg.bytesize, msg.bytesize))
16
+ @file.write(msg)
17
+ end
18
+
19
+ def stop
20
+ @file.close
21
+ end
22
+
23
+ private
24
+
25
+ def file_header
26
+ [
27
+ 0xa1b2c3d4, # Magic Number (little-endian)
28
+ 2, # Version Major
29
+ 4, # Version Minor
30
+ 0, # Timezone offset (GMT)
31
+ 0, # Timestamp accuracy
32
+ 65535, # Snapshot length
33
+ 1 # Link-layer header type (Ethernet)
34
+ ].pack('VvvVVVV')
35
+ end
36
+
37
+ def packet_record(timestamp, captured_length, original_length)
38
+ [
39
+ timestamp.to_i, # Timestamp seconds
40
+ (timestamp.usec || 0), # Timestamp microseconds
41
+ captured_length, # Captured packet length
42
+ original_length # Original packet length
43
+ ].pack('VVVV')
44
+ end
45
+ end
46
+ end
data/lib/redhound.rb CHANGED
@@ -7,3 +7,4 @@ require_relative 'redhound/packet_mreq'
7
7
  require_relative 'redhound/receiver'
8
8
  require_relative 'redhound/socket_builder'
9
9
  require_relative 'redhound/version'
10
+ require_relative 'redhound/writer'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redhound
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2024-11-05 00:00:00.000000000 Z
10
+ date: 2025-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Redhound is a pure Ruby packet analyzer that can be used to capture and
13
13
  analyze network packets.
@@ -38,6 +38,7 @@ files:
38
38
  - lib/redhound/receiver.rb
39
39
  - lib/redhound/socket_builder.rb
40
40
  - lib/redhound/version.rb
41
+ - lib/redhound/writer.rb
41
42
  - sig/redhound.rbs
42
43
  homepage: https://github.com/ydah/redhound
43
44
  licenses:
@@ -63,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  - !ruby/object:Gem::Version
64
65
  version: '0'
65
66
  requirements: []
66
- rubygems_version: 3.6.0.dev
67
+ rubygems_version: 3.6.2
67
68
  specification_version: 4
68
69
  summary: Pure Ruby packet analyzer
69
70
  test_files: []