eth_watcher 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2045277e6a97f896080806d4e3110d6b53437a2
4
- data.tar.gz: 83995e648f4a5a3d1adea66279a8ea38660e4d0a
3
+ metadata.gz: 9df132c69a97acf53d3e9b95f29ed32f0978340c
4
+ data.tar.gz: 49c517e329294a2cb2c10b5f437910fdf7e4f554
5
5
  SHA512:
6
- metadata.gz: 7323bef1a031ce739997279311fc27c83541138ce3d7efc1845b3d2a0698a69d8477696950a8705d9e2e9686401bd5e6054c960d2b1d8bbbe5962516c1550b8e
7
- data.tar.gz: 526b0f6d2334c4d50cb8be2faf13939c43d5c1b77f82d8b25367ebb31c514b22887dae4aa29b5b71083e01dc25f40039c4c2c207f6a06ccc6b9639a09041d036
6
+ metadata.gz: 77690c013738c1a15486ae70080ac4499b402b972607b09b263e3105b98f99673e795d04e4d62f2f114b5bf943391401e56c6d035a0ba81afc582c3013032dc9
7
+ data.tar.gz: 0b5b0dc237c0e7aadefe81a00caab1c56ea20fbb9b89cec858c61be1ee55ead29839ce14a928586ee2b82e72ae539f377eb1f8f277930cb833f61772cf702fae
@@ -0,0 +1,3 @@
1
+ module EthWatcher
2
+ VERSION = "1.0.5"
3
+ end
@@ -0,0 +1,54 @@
1
+ require "eth_watcher/version"
2
+ require 'thread'
3
+ require 'packetgen'
4
+ require 'trollop'
5
+
6
+ ARGV[0] = '-h' if ARGV.empty?
7
+
8
+ opts = Trollop::options do
9
+ opt :threads, "Use a given ammount of threads for parsing", default: 3, type: :int
10
+ opt :interface, "Use a given interface for packet capturing", default: Pcap.lookupdev, type: :string
11
+ opt :snap_length, "Use a given snapshot length for the capture", default: 65535, type: :int
12
+ opt :promiscuous, "Use promiscuous for the capture", default: true, type: :bool
13
+ end
14
+
15
+ module EthWatcher
16
+
17
+ @threads = Array.new
18
+ @parsed = Queue.new
19
+ @semaphore = Mutex.new
20
+
21
+ def self.start_capture(interface:, snaplen:, promisc:)
22
+ @capture = Pcap.open_live(interface, snaplen, promisc, 0)
23
+ end
24
+
25
+ trap "SIGINT" do
26
+ exit
27
+ end
28
+
29
+ def self.spawn_threads(count:)
30
+ count.times do
31
+ Thread.new do
32
+ loop do
33
+ begin
34
+ packet = PacketGen.parse(@capture.next_packet.to_s)
35
+ next unless packet.headers.first.ethertype
36
+ packet = packet.headers[0]
37
+ @semaphore.synchronize { puts packet.src << " -> " << packet.dst }
38
+ rescue
39
+ # YOLO!
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ EthWatcher.start_capture(interface: opts[:interface], snaplen: opts[:snap_length], promisc: opts[:promiscuous])
49
+
50
+ EthWatcher.spawn_threads(count: opts[:threads])
51
+
52
+ loop do
53
+ # CTL+C to exit program
54
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eth_watcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kent 'picat' Gruber
@@ -89,6 +89,8 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - bin/eth_watcher
92
+ - lib/eth_watcher.rb
93
+ - lib/eth_watcher/version.rb
92
94
  homepage: https://github.com/picatz/eth_watcher
93
95
  licenses:
94
96
  - MIT